[英]Wordpress widget for post specific content in sidebar
我正在寻找一个wordpress插件,该插件将允许我在侧栏添加特定于博客文章的段落。 创建帖子时,我将需要能够添加该文本。 那里有这样的东西吗? 我搜索失败。 谢谢
这不是我个人曾经做过的事情,但是请尝试一下。
摘要 :您将使用自定义字段添加一个段落,然后将其显示在小部件中。
详细资料 :
现在,当您撰写或编辑帖子时,您应该在“名称”下拉列表中看到此“ extra_paragraph”字段作为选项。
使用“自定义字段”,“文本小部件”和“简码”可以轻松解决此问题。
这些代码位于主题的functions.php
或者最好是在自定义插件中 。
1)启用文本小部件的简码
add_filter( 'widget_text', 'do_shortcode' );
2)定义简码,请阅读注释以获取详细信息
add_shortcode( 'mytext', 'so_13735174_custom_text_widget' );
function so_13735174_custom_text_widget( $atts, $content = null )
{
global $post;
// $post contains lots of info
// Using $post->ID many more can be retrieved
// Here, we are getting the Custom Field named "text"
$html = get_post_meta( $post->ID, 'text', true );
// Custom Field not set or empty, print nothing
if( !isset( $html ) || '' == $html )
return '';
// Print Custom Field
return $html;
}
3)在所需的侧边栏中添加一个文本小部件。
将标题留空,然后在内容中输入“简码”: [mytext]
。
4)现在,每个带有自定义字段名为text
页面或帖子将在Widget中打印其值。
5) $html
可以花哨并且可以使用多个自定义字段。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.