【发布时间】:2016-11-06 04:52:52
【问题描述】:
是否可以在 Wordpress 中为每个帖子使用自定义侧边栏而不将其编码到模板中?
我尝试使用 Flexible Posts Widget 插件,但无法正常工作。
【问题讨论】:
-
不,您必须在 single.php 中使用 if else 进行编码,或者您可以制作一个自定义侧边栏,接受帖子 ID 作为参数并返回与该帖子 ID 相关的侧边栏@SaifulIslamsaifultech
是否可以在 Wordpress 中为每个帖子使用自定义侧边栏而不将其编码到模板中?
我尝试使用 Flexible Posts Widget 插件,但无法正常工作。
【问题讨论】:
如果该侧边栏不存在,则需要 register_sidebar(), 然后到特定模板中的 get_sidebar( string $name = null )。 但是,如果相同的侧边栏出现在其他页面上,并且您只需要限制特定小部件的每个帖子的可见性, 尝试使用与小部件可见性相关的插件,即 https://wordpress.org/plugins/widget-visibility-without-jetpack/ 或者 https://wordpress.org/plugins/widget-visibility/ 找出更适合您需求的方法。 您将获得每个小部件的“可见性”按钮,然后您可以设置要显示的帖子。
【讨论】: