WordPress.org

Ready to get started?Download WordPress

Forums

Tweaking wp_list_pages child_of (4 posts)

  1. pf1
    Member
    Posted 4 years ago #

    Hi,

    I've created a site with a large footer that also acts as a sitemap with links to all the pages, I've added;

    <ul>
    <?php wp_list_pages('child_of=431&title_li='); ?>
    </ul>

    This gives the appropriate child of pages, but how do I include the parent page?

    <ul>
    <?php wp_list_pages('include=431&child_of=431&title_li='); ?>
    </ul>

    which gives the parent page but ignores the &child_of call.

    Any suggestions welcome.

    :D

  2. MichaelH
    Member
    Posted 4 years ago #

    <?php
    // use wp_list_pages to display parent and all child pages all generations (a tree with parent)
    $parent = 93;
    $args=array(
      'child_of' => $parent
    );
    $pages = get_pages($args);
    if ($pages) {
      $pageids = array();
      foreach ($pages as $page) {
        $pageids[]= $page->ID;
      }
    
      $args=array(
        'title_li' => 'Tree of Parent Page ' . $parent,
        'include' =>  $parent . ',' . implode(",", $pageids)
      );
      wp_list_pages($args);
    }
    ?>
  3. pf1
    Member
    Posted 4 years ago #

    Exactly what I was looking for, thanks.

    One last thing, how do I create it without a title?

    'title_li' => ' ' . $parent,
    I tried this, but that then put the page code in '390'

    I also tried removing this line completely, but that then put the title 'Pages' in.

    Thanks

  4. MichaelH
    Member
    Posted 4 years ago #

    'title_li' => '',

Topic Closed

This topic has been closed to new replies.

About this Topic