dsdfd2322 2014-04-25 05:45
浏览 58
已采纳

如何检查页面是否是Wordpress中另一个页面的直接或间接子页面?

I have a page with id 63. That page is having a number of child pages and each of the child pages is again having sub pages. In short page with id 63 is super parent to all the pages.

What I want is, I want to check whether the current page is a child of page with id 63. Either a direct child/child of child up to any level.

I am able to check the whether the page is a child of page 63. But not able to check the same for child of child pages.

I am using $post->post_parent == 63 to check whether the page is a child of page 63.

How can I check the same for all levels of pages ?

  • 写回答

2条回答 默认 最新

  • dongqie2028 2014-04-25 06:01
    关注
        $pageId= get_the_ID(); 
        function get_topmost_parent($post_id)
        {
            $parent_id = get_post($post_id)->post_parent;
            if($parent_id == 0)
            {
                return $post_id;
            }
            else
            {
                return get_topmost_parent($parent_id);
            }
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?