WordPress.org

Make WordPress Core

Opened 5 years ago

Last modified 3 months ago

#11095 new feature request

Format wp_list_pages and wp_page_menu without <li> tags

Reported by: zialingua Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version:
Component: Posts, Post Types Keywords: has-patch
Focuses: template Cc:

Description

Would that be possible to have the functions wp_list_pages and wp_page_menu with an option to display pages in a "flat" format like the functions wp_list_bookmarks or wp_tag_cloud or wp_get_archives?

Attachments (1)

11095.patch (15.7 KB) - added by stevegrunwell 3 months ago.
Adds 'format', 'before', and 'after' arguments to wp_list_pages()

Download all attachments as: .zip

Change History (5)

comment:1 @miqrogroove5 years ago

  • Component changed from General to Template
  • Keywords wp_list_pages wp_page_menu removed
  • Type changed from defect (bug) to feature request

comment:2 @nacin5 years ago

  • Milestone changed from Unassigned to Future Release

comment:3 @nacin13 months ago

  • Component changed from Template to Posts, Post Types
  • Focuses template added

@stevegrunwell3 months ago

Adds 'format', 'before', and 'after' arguments to wp_list_pages()

comment:4 @stevegrunwell3 months ago

  • Keywords has-patch added

These have limited use (especially when 'title_li' is present), but with the patch we can:

  1. Flatten the output (without re-ordering)
    <ul>
      <?php
        $args = array(
          'format' => 'custom',
          'before' => '<li class="%s">',
          'after' => '</li>',
          'title_li' => null
        );
        wp_list_pages( $args );
      ?>
    </ul>
    
    <!-- produces -->
    <ul>
      <li class="page_item page-item-1"><a href="http://src.wordpress-develop.dev?p=1">Parent Page</a></li>
      <li class="page_item page-item-3"><a href="http://src.wordpress-develop.dev?p=3">Child Page</a></li>
      <li class="page_item page-item-2"><a href="http://src.wordpress-develop.dev?p=2">Second Parent</a></li>
     </ul>
    
  1. Wrap links in other elements
    <?php
      $args = array(
        'format' => 'custom',
        'before' => '<span class="%s">',
        'after' => '</span>',
        'title_li' => null
      );
      wp_list_pages( $args );
    ?>
    
    <!-- produces -->
    <span class="page_item page-item-1"><a href="http://src.wordpress-develop.dev?p=1">Parent Page</a></span>
    <span class="page_item page-item-3"><a href="http://src.wordpress-develop.dev?p=3">Child Page</a></span>
    <span class="page_item page-item-2"><a href="http://src.wordpress-develop.dev?p=2">Second Parent</a></span>
    
  1. Add icons, entities, or whatever other items (that should most likely be CSS pseudo-elements):
    <?php
      $args = array(
        'format' => 'custom',
        'before' => '*&nbsp;',
        'title_li' => null
      );
      wp_list_pages( $args );
    ?>
    
    <!-- produces -->
    *&nbsp;<a href="http://src.wordpress-develop.dev?p=1">Parent Page</a>
    *&nbsp;<a href="http://src.wordpress-develop.dev?p=3">Child Page</a>
    *&nbsp;<a href="http://src.wordpress-develop.dev?p=2">Second Parent</a>
    

Patch also adds tests for wp_page_menu().

Note: See TracTickets for help on using tickets.