2012-12-06 190 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可以看中,可以使用多個自定義字段。