2011-01-11 68 views
1

我正在調用一個WordPress頁面的類別,並使用PHP調用在右側導航欄中顯示它們。我是一般的PHP和網絡編程的新手。有沒有一種方法可以使用特定的PHP調用或if-loop將類別分成兩部分。Wordpress導航幫助

本質上,我想顯示自定義子標題下的特定類別,以更好地組織網站。任何幫助,我目前使用下面的腳本,以顯示我的類別:

<ul><?php wp_list_categories('show_count=1&title_li='); ?></ul> 

這裏是我的參考網站:http://www.merrimentdesign.com

回答

1

嘗試使用上面的代碼的兩倍。每次,您都可以使用其他函數參數將輸出限制爲某些類別。有關定製函數輸出的各種方法,請參見http://codex.wordpress.org/Template_Tags/wp_list_categories

例如,你可以使用:

<ul><?php wp_list_categories('show_count=1&title_li=&child_of=100'); ?></ul> 
// where 100 is the parent id of all of the categories you want to print. 

<ul><?php wp_list_categories('show_count=1&title_li=&exclude_tree=100'); ?></ul> 
// and then show everything, but children of 100 

或者簡單地用每一次的第一個字符串多次指定不同的父類標識。

+0

謝謝。這工作。非常感激。 – TopChef 2011-01-12 17:11:29

1

目前爲止,您最好的選擇是使用WordPress中的新菜單功能。這是死直截了當地建立在你的主題:

add_theme_support('menus'); 

add_action('init', 'register_my_menus'); 

function register_my_menus() { 
    register_nav_menus(
     array(
      'public-menu' => __('Public Menu'), 
      'sidebar-public-menu' => __('Sidebar Public Menu'), 
      'sidebar-members-menu' => __('Sidebar Members Menu'), 
      'sidebar-staff-menu' => __('Sidebar Staff Menu'), 
      'footer-menu' => __('Footer Menu') 
     ) 
    ); 
} 

的地方,在您的functions.php文件(顯然改變了你的要求)。

然後在你的模板文件 - 可能的sidebar.php你會想是這樣的:

<?php wp_nav_menu(array('theme_location' => 'sidebar-staff-menu', 'container' => false)); ?> 

然後去到WordPress的後端(您可溼性粉劑管理員),然後轉到外觀>菜單瞧,你可以拖放你的類別到你的心臟的內容!

有用的鏈接:http://justintadlock.com/archives/2010/06/01/goodbye-headaches-hello-menus

閱讀,賈斯汀Tadlock是真棒。

祝你好運。