如果页面显示菜单的孙子

if Grandchild of page display menu

希望你能指出我做错了什么。我的侧边栏中有一个小部件区域,仅用于显示我网站的一部分。

if(is_page(199) || $post->post_parent == '199') {
dynamic_sidebar( 'widget-area' );
}

我得到的是实际页面及其子页面,这很好,虽然我更改了创建孙子部分的结构,但现在孙子不会显示小部件区域。

这应该有帮助

https://codex.wordpress.org/Function_Reference/get_post_ancestors

使用 post ID 有点不好...但那是另一回事了 :)

    $ancestors = get_post_ancestors( $post );

    if ( is_page( 199 ) || in_array( '199', $ancestors ) )
    {
       echo "This is My Page or one of its descendants";
    }