dongsilu2237 2015-06-30 07:21
浏览 157
已采纳

Wordpress - 在所述子页面上显示父页面的子页面

I have the following hierarchical order:

Parent Page
     Child Page 1
     Child Page 2
     Child Page 3

I use the following PHP snippet to show all child pages on the parent page in a side navigation:

wp_list_pages('title_li=&child_of='.$post->ID.'&echo=1');

Now to my question:

How can I modify the snippet that it also displays the side navigation on the child pages? Somehow: 'Go to your parent page, collect all child pages and display it where you are, on a child page'.

Thanks for reading!

  • 写回答

1条回答 默认 最新

  • dtbam62840 2015-06-30 07:47
    关注
    wp_list_pages('title_li=&child_of='.$post->post_parent.'&echo=1');
    

    This snippet will return the current page and its siblings. However this will only return the children of the current page's parent. If you need to get pages for a deeply nested hierarchy you should use:

    global $post;
        /* Get an array of Ancestors and Parents if they exist */
    $parents = get_post_ancestors( $post->ID );
        /* Get the top Level page->ID count base 1, array base 0 so -1 */ 
    $id = ($parents) ? $parents[count($parents)-1]: $post->ID;
    wp_list_pages('title_li=&child_of='.$id.'&echo=1');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 关于用python写支付宝扫码付异步通知收不到的问题
  • ¥50 vue组件中无法正确接收并处理axios请求
  • ¥15 隐藏系统界面pdf的打印、下载按钮
  • ¥15 MATLAB联合adams仿真卡死如何解决(代码模型无问题)
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决
  • ¥15 python中transformers可以正常下载,但是没有办法使用pipeline
  • ¥50 分布式追踪trace异常问题
  • ¥15 人在外地出差,速帮一点点
  • ¥15 如何使用canvas在图片上进行如下的标注,以下代码不起作用,如何修改