【发布时间】:2012-05-02 15:31:33
【问题描述】:
我有一个菜单问题需要帮助。
我正在使用主题为 211 的 wordpress 3.3.2。
我正在使用两个模板,默认的 wordpress 展示和一个名为 products 的自定义页面模板。
我目前有这个子导航树(展示模板):
- -市场与产品
- 农业
- 航空航天
- 防御
- 工业
我用来得到上述结果的代码是:
<?php
//$children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=1&depth=1');
if($post->post_parent && $post->post_parent!=0){
$children = wp_list_pages("title_li=&sort_column=menu_order&child_of=".$post->post_parent."&echo=0&depth=2");
}else{
$children = wp_list_pages("title_li=&sort_column=menu_order&child_of=".$post->ID."&echo=0&depth=1");
}
if ($children) { ?>
<div id="subNav">
<ul>
<?php echo $children; ?>
</ul>
</div>
<?php } ?>
当我选择农业页面(产品模板)时,我会看到这样的结构:
- 营销与产品
- 农业
- 孙子页面 1
- 孙子页面 2
- 航空航天
- 孙子页面 1
- 孙子页面 2
- 防御
- 工业
- 农业
农业孙子页面已显示,但航空孙子页面应隐藏。
我当前使用的代码是:
<?php
//$children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=1&depth=1');
// && $post->post_parent!=0
if($post->post_parent){
//siblings
$textTest = 'siblings';
$children = wp_list_pages("title_li=&sort_column=menu_order&child_of=".$post->post_parent."&echo=0&depth=2");
}else{
$textTest = 'children';
$children = wp_list_pages("title_li=&sort_column=menu_order&child_of=".$post->ID."&echo=0&depth=1");
}
if ($children) { ?>
<div id="subNav">
<? echo $textTest;?>
<ul>
<?php echo $children; ?>
</ul>
</div>
<?php } ?>
所以我想知道的是;给定: 营销页面的父级为 0 它有孩子航空航天和农业 他们也有孩子(营销的孙子)
有什么方法可以显示: 营销之子在该页面上时 农业的孩子(例如)在该页面或其中一个子页面上 - 这样只有这些孙子显示以及农业的兄弟姐妹(营销的孩子),而不是它的兄弟姐妹的孩子?
任何帮助表示赞赏。 :)
【问题讨论】:
标签: php wordpress menu children