2017-05-09 101 views
0

我有一个页面的结构是这样的:显示同级页,包括当前页面中的WordPress

  • 食品

    • 奶酪
    • 水果
    • 肉类
    • 糖果
  • 音乐

    • 舞蹈
    • 民间

当一个孩子页面上,我想,显示了兄弟姐妹,包括当前网页的菜单。例如,如果我是“果”页面上我想看看: 奶酪水果肉类糖果

“果”不应该有一个链接,因为它是当前页面。

我已经试过这一点,但它不包括当前页面:

<?php 
    wp_list_pages(array(
'child_of' => $post->post_parent, 
'exclude' => $post->ID, 
'depth' => 1 
)); 
?> 

回答

0

您当前的代码必须排除的说法,只是删除'exclude' => $post->ID,所以你可以看到当前的页面了。 ..

<?php 
    wp_list_pages(array(
'child_of' => $post->post_parent, 
'depth' => 1 
)); 
?> 

并作出unclickeble请使用以下风格

<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 
)); 
?> 
+0

完美,谢谢!我添加了这个来排除列表标题''title_li'=>''' – user1681447

+0

不客气:)请投票,如果有用的话:) – Ashkar

+0

对不起,我试过,但没有足够的声望:( – user1681447

0

以下是你需要做的逻辑。首先得到这个职位,父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>'; 
相关问题