• Resolved xmatter

    (@xmatter)


    let’s use this scenario:

    parent page namedMUSIC (music.php)
    child page of MUSIC named DANCE (music_dance.php)
    child page of DANCE named THEORY (music_dance_theory.php)

    Now… when a user clicks MUSIC, all child pages display (current code to display the child page DANCE):
    <?php wp_list_pages('child_of=77&sort_column=post_title&title_li=&depth=1') ?>

    and… when DANCE is clicked, all child pages display (current code to display the child page THEORY):

    <?php
    $children = wp_list_pages('sort_column=post_title&title_li=&child_of='.$post->ID.'&echo=0');
    if ($children) { ?>
        <ul>
            <?php echo $children; ?>
        </ul>
    <?php } ?>

    Question: As you can see, i created a separate php template file for each instance. Is there a way to only create 1 simple template that will work for this scenario? a single php template just for the parent pages?

    Reason: The reason i ask is because i plan on having 60 parent pages, all with 30+ children, and then those children will have 30+ children. I do not want to create 180 page templates.

    Any help is appreciated…

    P.S. When clicking the parent page (MUSIC) the only results i want displayed are the child page titles and not the children of the 1st level child page.

Viewing 7 replies - 1 through 7 (of 7 total)
  • <?php
      $children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0');
      if ($children) { ?>
      <ul>
      <?php echo $children; ?>
      </ul>
      <?php } ?>

    https://codex.www.ads-software.com/Function_Reference/wp_list_pages#List_Sub-Pages

    Thread Starter xmatter

    (@xmatter)

    that is the current code that i am using as stated in most 1st post, but that brings up all sub pages.

    parent
    -sub
    –subsub

    when parent clicked, page shows sub
    when sub clicked, page shows subsub

    can this be put into 1 single template for all 30 parent pages to draw from. each parent page of course has 30 child pages related to that single parent.

    Thread Starter xmatter

    (@xmatter)

    what i meant to say there, is that when i click a parent page, i only want the parent’s 1st level sub pages… not the sub sub pages as well.

    what would the code be for that? Thanks!

    when parent clicked, page shows sub
    when sub clicked, page shows subsub

    I thought that was what you wanted…

    Thread Starter xmatter

    (@xmatter)

    it is, but it brings all sub pages of parent (good) and sub sub pages of parent (not good). Maybe there is something wrong with my page.php file?

    here is a copy of my page.php, you will notice i am testing a few codes, so please watch for the commented out parts.

    [Code moderated as per the Forum Rules. Please use the pastebin]

    thanks for your help!

    Try:
    $children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0&depth=1');

    Thread Starter xmatter

    (@xmatter)

    that worked, thanks! i was putting depth=1 within 1’title_li&child_of=’1

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘custom page template help’ is closed to new replies.