• Hi there, I’m running a site on which there are several levels of pages.

    so for example:
    A page called ‘Diagnoses’, with a subpage ‘diagnosis in neurology’ which has several subpages-> i.e MRI, X-Ray and contrast-MRI.

    The third level pages (MRI, X-Ray and contrast MRI) use a different lay-out/page template as the two top level pages ‘Diagnosis’ and ‘Diagnosis in neurology’.

    Of course in my page template I check for a parent, but I actually have to check if it is a sub sub page… any help for that?

Viewing 10 replies - 1 through 10 (of 10 total)
  • Thread Starter alfakappa

    (@alfakappa)

    Thanks… I can see how that relates, but I still cannot figure out the code to use…

    I need someting like this:

    <?php if {is subpage of subpage} [show all kind of content fields]}

    else { show only title and content }

    ;?>

    Any kick start on that?

    Thread Starter alfakappa

    (@alfakappa)

    Got that one as well esmi, but it is not testing for sub of sub – or.. at least I cannot see how…

    Try:

    $top_ancestor = end( get_post_ancestors($this_page) );
    if( is_page( 'Diagnoses' ) ) {
    	// the current page is a descendant of the Diagnoses page
    	[ do stuff ]
    }
    Thread Starter alfakappa

    (@alfakappa)

    In that case I would have to list al the second level pages which are appr. >50 pages.

    Also, if there will be added an extra page, it won’t automatically take the right template part. So is there a way to change ‘Diagnosis’ to a more dynamic part such as ‘child of diagnosis, child of woman & Child or child of dermatology’

    (there are 4 top level pages, each of them with about 10 subpages and every subpages with appr another 15 subpages)

    In that case I would have to list al the second level pages which are appr. >50 pages.

    No. That code should determine if any page is a child, grandchild, great-grandchild etc of the top level Diagnoses page. The level is no longer an issue.

    Thread Starter alfakappa

    (@alfakappa)

    ok, tried this one; only it is not a page, it’s a CPT ?? sorry that i forgot to mention that…

    should i us is_post instead of is_page?

    So these are Posts – not Pages? If so, then none of the above code will work. It’s only for static Pages.

    Thread Starter alfakappa

    (@alfakappa)

    auch… no sorry… it’s a CPT…. really sorry…

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘check if it is a subpage of a subpage?’ is closed to new replies.