我有这样的页面结构:
- Cheese
- Fruit
- Meat
- Sweets
- Rock
- Dance
- Folk
在子页面上,我想要一个显示兄弟姐妹的菜单,包括当前页面。例如,如果我在“水果”页面上,我想看看:Cheese果树Meat Sweets
“水果”不应该有链接,因为它是当前页面。
我试过了,但它不包括当前页面:
<?php
wp_list_pages(array(
'child_of' => $post->post_parent,
'exclude' => $post->ID,
'depth' => 1
));
?>发布于 2017-05-09 05:24:03
您当前的代码有排除参数,只需删除'exclude' => $post->ID,这样您也可以看到当前页面.
<?php
wp_list_pages(array(
'child_of' => $post->post_parent,
'depth' => 1
));
?>为了不太陈词滥调,请使用下面的样式
<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
));
?>发布于 2017-05-09 05:00:49
这是你需要做的逻辑。首先获取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>';https://stackoverflow.com/questions/43860647
复制相似问题