• Hi,

    I’m working with wordpress as a cms so I only have pages and not posts. On my pages I also have permalinks switched on so my pages don’t have ID’s anymore they have actual names.

    My problem is I want to list all sub-pages of a parent page and currently I can’t seem to get my code to work correctly. I’m using a plugin to execute the php in a page (exec-php I believe).

    <?php
    // use wp_list_pages to display parent and all child pages all generations (a tree with parent)
    $parent = [what do I put here???];
    $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);
    }
    ?>

    This is the code I’m using straight from the WordPress documentation. If I replace ‘What do I put here?’ with a 0 it displays all my pages of the site.

    Help much needed tnanks.

    DD

Viewing 6 replies - 1 through 6 (of 6 total)
  • so my pages don’t have ID’s anymore

    Oh yes they do! WP still uses ids internally – irrespective of what custom permalink is displayed. So you need to find the id of the parent Page.

    How do I find an id?

    Thread Starter double_dd

    (@double_dd)

    Thanks for the quick response. I’m not sure where you’re pointing me to. One of the plugins as the other options don’t work?

    Thread Starter double_dd

    (@double_dd)

    EDIT – Thanks for the pointer. I’ve installed one of the plugins and I’m halfway there. I just need to get rid of the parent page from the list. Any ideas?

    You might be better off using another approach. There are a few listed on this Codex page.

    Thread Starter double_dd

    (@double_dd)

    I was just about to re-post. Thanks for you help you’ve been great.

    I’ve replaced that mass of code with <?php wp_list_pages('child_of=16'); ?>

    simple really now I get it ha

    Glad you got it sorted. 🙂

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘wp list pages with permalinks’ is closed to new replies.