我的設置如下:
- 自定義後類型,稱爲「客戶」
- 2導航級別(獨立,第二級只顯示如果當前頁面有父母/子女)
- 一個頁面調用客戶
- 客戶端的職位有一個自定義模板(單clients.php)WP自定義後類型 - 設置頁面父
我要讓任何「客戶」發佈客戶端頁面的子頁/孩子,所以導航顯示器正確地在客戶端頁面(它會自動列出子頁面),並且很容易添加新的客戶端。
我發現了幾個腳本,但他們都沒有做到我想要的。
這裏是我的子navig代碼的主要部分:
<nav id='content_clients_navig' class='navig_general'>
<ul>
<?php
global $post;
//determine which navig should be displayed
//if post has parent, display parent navig
//else display the current post's navig
$navig_display = ($post->post_parent) ? $post->post_parent : $post->ID;
$menu_args = array(
'child_of' => $navig_display,
'title_li' => ''
);
wp_list_pages($menu_args);
?>
</ul>
</nav>
我在我的模板文件中插入這段代碼調用它:
<?php if (has_subnavig()) get_template_part('part', 'subnavig'); ?>
這裏是has_subnavig:
function has_subnavig()
{
global $post;
if(is_page() && $post->post_parent){
return true;
}else{
$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
};
if($children){
return true;
}else{
return false;
};
}
你是如何列出你的二級導航?也許你需要更改該代碼。你使用WordPress的菜單? – martinczerwi
我編輯的主要帖子,檢查出:) –
任何其他的想法? –