php 如何通过其短代码在 Wordpress 帖子/页面上添加小部件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18506146/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 17:40:45  来源:igfitidea点击:

How to add a widget by its shortcode on Wordpress posts / pages?

phpwordpresswordpress-pluginshortcode

提问by codepixlabs

Is there any way we can assign a shortcode to already created widget and later use that

有什么方法可以为已经创建的小部件分配一个短代码,然后再使用它

shortcode in our specific posts and pages to show that widget instead of trivial method of

我们特定帖子和页面中的短代码来显示该小部件,而不是简单的方法

showing widgets in sidebar ? I googled about this stuff didn't find anything relative.

在侧边栏中显示小部件?我用谷歌搜索这些东西没有找到任何相关的东西。

Any suggestion would be welcome!

欢迎任何建议!

回答by Balaji Kandasamy

Yes, You can call widget in Post/Page using shortcode. Follow this link to establish a system like that. http://digwp.com/2010/04/call-widget-with-shortcode/

是的,您可以使用简码在帖子/页面中调用小部件。按照这个链接建立一个这样的系统。 http://digwp.com/2010/04/call-widget-with-shortcode/

回答by Richard Duncan

This might be relevant.

这可能是相关的。

Widgets on Pages

页面上的小部件

https://wordpress.org/plugins/widgets-on-pages/

https://wordpress.org/plugins/widgets-on-pages/

Observations and two questions:

观察和两个问题:

This plugin allows insertion of 1 or "sets" of widgets via shortcode into pages, posts, (and Custom post types?) and it will also save a list of configured shortcodes~sets. VERY handy!

该插件允许通过短代码将 1 个或“组”小部件插入页面、帖子(和自定义帖子类型?),并且它还将保存配置的短代码列表。非常便利!

When comparing its features to the plugin Widgets Shortcode, that plugin does not provide a means to save "sets" of plugins, rather it seems to focus on inserting widgets individually. In fact, it inserts the shortcode for each widget in the bottom edge of each widget and it assigns different shortcodes to each instance of a widget. Also nice.

将其功能与插件 Widgets Shortcode 进行比较时,该插件不提供保存插件“集合”的方法,而是似乎专注于单独插入小部件。事实上,它在每个小部件的底部边缘插入每个小部件的短代码,并为小部件的每个实例分配不同的短代码。也不错。

https://wordpress.org/plugins/widget-shortcode/

https://wordpress.org/plugins/widget-shortcode/

I like the granularity Widgets Shortcode provides with an individual shortcode for every instance of every widget. When running it and your plugin simultaneously even widgets saved in your plugin's "sets" are still assigned individual shortcodes. Those individual shortcodes allow using a specific widget out of a "set" in a different location without needing to create an additional instance of the widget as it appears would be required with your plugin.

我喜欢 Widgets Shortcode 为每个小部件的每个实例提供一个单独的短代码的粒度。当同时运行它和您的插件时,即使是保存在插件“集合”中的小部件仍会被分配单独的短代码。这些单独的短代码允许在不同位置使用“集合”中的特定小部件,而无需创建该小部件的附加实例,因为它似乎是您的插件所需要的。

Incidently, for anyone who wants both of these features, these two plugins play very nicely together on one of our WP 4.0 Multisite installations with 50+ sites and even on a site using the theme Make.

顺便说一句,对于想要这两个功能的任何人来说,这两个插件在我们的 WP 4.0 多站点安装之一上与 50 多个站点甚至在使用主题 Make 的站点上配合得非常好。

FYI: We also tested amr shortcode any widget, but had some issues with it and rather than troubleshoot it we moved on. To be fair, we were testing quickly on a site with over 160 plugins active. Yes, 160 plugins. I know, I know, but think about it for a minute. Any plugin that you can activate into that mix of 160 plugins and it does not break things or introduce issues, then it suggests a good probability of it being troublefree to use.... well at least until the next round of WP updates. :)

仅供参考:我们还测试了 amr 短代码任何小部件,但遇到了一些问题,我们没有对其进行故障排除,而是继续进行。公平地说,我们在一个有 160 多个活跃插件的站点上进行了快速测试。是的,160 个插件。我知道,我知道,但想一想。您可以将任何插件激活到 160 个插件的组合中,并且不会破坏事物或引入问题,那么它表明它很可能可以无障碍使用......至少在下一轮 WP 更新之前。:)

We also tested Widgetize Pages Light and its pro version Sidebar & Widget Manager and had no issues with either. However, if only seeking to insert widgets into pages and posts these plugins seem like overkill as they provide additional page layout functions that may duplicate theme functions and/or other plugin functions.

我们还测试了 Widgetize Pages Light 及其专业版 Sidebar & Widget Manager,两者都没有问题。但是,如果只是试图将小部件插入页面并发布这些插件,那么这些插件似乎有点过分,因为它们提供了额外的页面布局功能,这些功能可能会重复主题功能和/或其他插件功能。

I was looking for a "widgets in pages" plugin that provides a TinyMCE button to insert the widget shortcodes.

我正在寻找一个“页面中的小部件”插件,它提供了一个 TinyMCE 按钮来插入小部件短代码。

Can anyone recommend one that has a TinyMCE button to insert the widget shortcodes in pages, posts and CPTs?

谁能推荐一个有 TinyMCE 按钮的插件,可以在页面、帖子和 CPT 中插入小部件短代码?

Ultimately I selected Widgets On Pages as having the best combination of features for this application. Its simple to understand, easy to use, versatile and has worked flawlessly for us, even along side Widgets Shortcode.

最终,我选择了 Widgets On Pages 作为此应用程序功能的最佳组合。它易于理解、易于使用、用途广泛,并且为我们提供了完美的工作,甚至可以与 Widgets Shortcode 一起使用。

回答by Jothi Kannan

You can do it by wordpress WordPress Widgets Shortcodeplugin, you can Embed any widget area/dynamic sidebar to your pages/posts using this plugin as a shortcode

您可以通过 wordpress WordPress Widgets Shortcode插件来实现,您可以使用此插件作为短代码将任何小部件区域/动态侧边栏嵌入到您的页面/帖子中

回答by OpenWebWar

edit widgets in wp :

在 wp 中编辑小部件:

file in @ wp-includes/widgets.php: register_widget()

@ wp-includes/widgets.php 中的文件: register_widget()

in source view sample : public function register( $widget_class ) { $this->widgets[$widget_class] = new $widget_class(); }

在源代码视图示例中: public function register( $widget_class ) { $this->widgets[$widget_class] = new $widget_class(); }