• How can I rename elements in wp_list_pages()?

    Essentially, I am using wp_list_pages in a widget to generate a list of galleries based on the current page. For example, if the user is on a page that is a landscape gallery, then the widget will display the Heading “Galleries” and then display the parent and all children of the Landscape page.

    Currently it list the page’s titles. However I’d like to rename the pages in the list so that they always display ‘gallery 1’, ‘gallery 2’, etc.
    Here’s my widget code:

    // use wp_list_pages to display parent and all child pages all generations (a tree with parent)
    $parent = get_top_parent_page_id();
    $args=array(
      'child_of' => $parent
    );
    $pages = get_pages($args);
    if ($pages) {
      $pageids = array();
      foreach ($pages as $page) {
        $pageids[]= $page->ID;
      }
    
      $args=array(
        'title_li' => '',
        'include' =>  $parent . ',' . implode(",", $pageids)
      );
      echo '<div class="sidebargallery">';
      echo '<h2>Galleries</h2>';
      wp_list_pages($args);
      echo '</div>';
    }

    This Currently displays:
    Galleries
    Landscape
    Landscape_child1
    Landscape_child2

    I’d like it to display (no matter if they are in a landscape, people, aniamls, or other topic):
    Galleries
    Gallery 1
    Gallery 2
    Gallery 3

    I thought I could either replace the values in the array, but I believe these are two different elements of args[]. The second thought was to give my div an id and use javascript to replace all the li elements inside of it, which I only have a slight idea of how to do.

    any help would be great.
    thanks.

  • The topic ‘rename page_items in wp_list_pages’ is closed to new replies.