在Wordpress中显示同级页面,包括当前页面
我的页面结构如下:在Wordpress中显示同级页面,包括当前页面,wordpress,wordpress-theming,Wordpress,Wordpress Theming,我的页面结构如下: 食物 奶酪 果 肉 糖果 音乐 摇滚乐 跳舞 民间的 当在子页面上时,我想创建一个显示同级(包括当前页面)的菜单。例如,如果我在“水果”页面上,我希望看到: 奶酪水果肉糖果 “水果”不应该有链接,因为它是当前页面 我尝试过这个,但它不包括当前页面: <?php wp_list_pages(array( 'child_of' => $post->post_parent, 'exclude' => $post->ID, 'dep
- 食物
- 奶酪
- 果
- 肉
- 糖果
- 音乐
- 摇滚乐
- 跳舞
- 民间的
<?php
wp_list_pages(array(
'child_of' => $post->post_parent,
'exclude' => $post->ID,
'depth' => 1
));
?>
以下是您需要执行的逻辑。首先获取post父ID:
$post_parent_id = wp_get_post_parent_id( $post_ID );
然后获取父页面的子级:
$my_wp_query = new WP_Query();
$all_wp_pages = $my_wp_query->query(array('post_type' => 'page', 'posts_per_page' => '-1' , 'post__in' => array($post_parent_id)));
$children = get_page_children( $post_parent_id, $all_wp_pages );
echo '<pre>' . print_r( $children, true ) . '</pre>';
$my_wp_query=new wp_query();
$all_wp_pages=$my_wp_query->query(数组('post_type'=>'页面','posts_per_pages'=>'-1','post_in'=>数组($post_parent_id));
$children=get_page_children($post_parent_id,$all_wp_pages);
回显“”。打印(儿童,真实)。”;
您当前的代码有exclude参数,只需删除'exclude'=>$post->ID
,就可以看到您当前的页面
<style type="text/css">
.current_page_item a{
pointer-events: none;
cursor: default;
color: #000;
}
</style>
要使其不可拾取,请使用以下样式
<style type="text/css">
.current_page_item a{
pointer-events: none;
cursor: default;
color: #000;
}
</style>
<?php
wp_list_pages(array(
'child_of' => $post->post_parent,
'depth' => 1
));
?>
.当前页面\项目a{
指针事件:无;
游标:默认值;
颜色:#000;
}
所以最后的代码是
.当前页面\项目a{
指针事件:无;
游标:默认值;
颜色:#000;
}
太好了,谢谢!我添加此项是为了排除列表标题'title\u li'=>''
欢迎:)如果有用,请向上投票:)抱歉,我尝试过,但没有足够的声誉:(
<style type="text/css">
.current_page_item a{
pointer-events: none;
cursor: default;
color: #000;
}
</style>
<?php
wp_list_pages(array(
'child_of' => $post->post_parent,
'depth' => 1
));
?>