2012-12-06 191 views

回答

3

这不是我亲自做过的事情,但试试这个。

摘要:您将使用自定义字段添加一个段落,然后将其显示在小部件中。

详细

  • 首先,确保自定义字段已启用。编辑帖子,然后点击页面右上角的“屏幕选项” 。如果未选中“自定义 字段”,请检查它。您现在应该在帖子编辑器下方看到一个自定义字段 区域。
  • 想出您的自定义字段的名称。也许 “extra_paragraph”。现在将其放在自定义 字段区域的“名称”字段中。
  • 将您的段落写入自定义字段区域的“值”字段中。
  • 安装Custom Field Widget plugin,将其设置为显示此新的“extra_paragraph”字段 。当您编写或编辑帖子,你应该看到这个“extra_paragraph”字段中的“名”下拉选项(窗口小部件似乎是未经测试与WordPress的新版本使你的手指!)

现在。

2

这可以很容易地解决使用自定义字段,文本小工具和简码。
这段代码出现在主题的functions.php中,或者最好在custom plugin之内。

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可以看中,可以使用多个自定义字段。