简体   繁体   English

WordPress在特定帖子/页面上的侧边栏中显示内容

[英]Wordpress Display Content in Sidebar on Specific Post/Pages

I am not sure exactly what I am looking for in the api so I'm going to ask here. 我不确定在api中到底要寻找什么,因此我将在这里询问。 On a post/page, I want the ability to have a piece of text display on the sidebar ONLY that content. 在帖子/页面上,我希望能够仅在侧边栏上显示一段文本。 The content to be display is to be set as an attribute or something similar in the edit area of that post only. 仅在该帖子的编辑区域中将要显示的内容设置为属性或类似内容。

Is there a way of doing this and where do I look in the api? 有没有办法做到这一点,我在api的哪儿看?

Using a text widget as already mentioned, you can use the Widget Logic plugin and use an if statement to display that widget only on the post you want. 如前所述,使用文本窗口小部件,您可以使用窗口小部件逻辑插件,并使用if语句仅在所需的帖子上显示该窗口小部件。

http://wordpress.org/extend/plugins/widget-logic/ http://wordpress.org/extend/plugins/widget-logic/

If you are looking for logic to do this here it is: 如果您正在寻找执行此操作的逻辑,则为:

  1. In your post you have access to custom variable so create one which you will then access in sidebar and if that is true then a widget can be shown else it does not need to be. 在您的帖子中,您可以访问自定义变量,因此请创建一个自定义变量,然后您将在侧边栏中访问该变量,如果为true,则可以显示一个小部件,而不必这样做。
  2. You need to access this custom variable outside post loop which you can use by using global variables and assign its value to that. 您需要在循环后访问此自定义变量,您可以使用全局变量来使用该变量并将其值分配给该变量。
  3. In your widget you need to look at globalvariables and check the value of above and then do your if else logic to show or hide parts of content in sidebar. 在小部件中,您需要查看globalvariables并检查上述值,然后执行if if else逻辑以在侧边栏中显示或隐藏部分内容。

A good starting point for this can be this tutorial which does show twitter or facebook posts based on custom variable on post. 为此的一个很好的起点可以是本教程该教程的确根据帖子中的自定义变量显示Twitter或Facebook帖子。

您可以使用此插件,然后选择页面,帖子类型或什至用逗号分隔的帖子ID列表http://wordpress.org/plugins/display-widgets/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM