• tinfish

    (@tinfish)


    Hi there,

    I wonder if anyone can help me.

    I have a large WP install with over 1600+ pages and a complex page hierarchy. I would like to find out if the current page just has children or does it have grandchildren (or no children).

    Background
    Currently the page loop checks to see if the page has children or else not. If the current page does have children then a table is shown containing,
    Title | WordCount | Excerpt (comments link in future) for the current pages children.
    Else the_content is displayed

    If the current page has grandchildren (or deeper) then within the table the wordcount is null and there is no excerpt as the child pages contain no actual WP db content. On the ‘current page’ I would like to show a more appropriate table when there are grandchildren so the word count and excerpt aren’t empty.

    http://www.startrekdeepspacenine.org/encyclopedia/

    The Issue
    I need to ascertain if
    the current page has no children (my current ‘else’ in the loop)
    the current page has children and no grandchildren
    the current page has children and grandchildren (from any child page)

    Finding the current page depth doesn’t suffice as the depth 2 page may have grandchildren or may not and so need a different table.

    The only output I need is a numeric value so I can create a conditional loop based on that output (or do the working with the conditional statement itself).

    Does anyone have a code snippet/function for this?

    More Ramblings
    I have managed to achieve what I want in terms of conditional nav in the sidebar utilising the discussion and plug-ins that are out there; there is little to no info around about exactly what I’m after here..

    I’m not a PHP coder but know (guess) enough to hack & slash my way around. Theres probably a solution within some of those plug-ins but I cant pull it out.

    I think that the queries needed to do this might be quite ‘heavy’/numerous – I intend to cache the entire site (over the long term) so this isn’t necessarily an issue.

    So can anyone help me out with this?
    Is my query even understandable?!?

    thanks & regards
    tinfish

  • The topic ‘Does current page have just children or grandchildren?’ is closed to new replies.