WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 5 months ago

#11095 closed enhancement (fixed)

Format wp_list_pages and wp_page_menu without <li> tags

Reported by: zialingua Owned by: wonderboymusic
Milestone: 4.4 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 (2)

11095.patch (15.7 KB) - added by stevegrunwell 17 months ago.
Adds 'format', 'before', and 'after' arguments to wp_list_pages()
11095.2.patch (1.1 KB) - added by stevegrunwell 8 months ago.
Adds inline docs to code committed by @wonderboymusic in 34200

Download all attachments as: .zip

Change History (17)

#1 @miqrogroove
6 years ago

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

#2 @nacin
6 years ago

  • Milestone changed from Unassigned to Future Release

#3 @nacin
2 years ago

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

@stevegrunwell
17 months ago

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

#4 @stevegrunwell
17 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().

#5 @wonderboymusic
8 months ago

  • Keywords needs-patch added; has-patch removed
  • Milestone changed from Future Release to 4.4
  • Type changed from feature request to enhancement

Seems like wp_page_menu() needs to be able to accept 'walker' and remove some of the hardcoded HTML bits. wp_list_pages() already accepts 'walker'

#6 @wonderboymusic
8 months ago

  • Owner set to wonderboymusic
  • Resolution set to fixed
  • Status changed from new to closed

In 34200:

Allow wp_page_menu() to accept 'walker', 'before', and 'after' to allow custom markup.

Fixes #11095.

#7 @DrewAPicture
8 months ago

  • Keywords needs-docs added
  • Resolution fixed deleted
  • Status changed from closed to reopened

Documentation for the three new arguments needs to be added to the hash notation for $args. Also, a changelog entry, please :-)

@stevegrunwell
8 months ago

Adds inline docs to code committed by @wonderboymusic in 34200

#8 @stevegrunwell
8 months ago

  • Keywords needs-patch needs-docs removed

#9 @DrewAPicture
8 months ago

  • Keywords has-patch added

#10 @SergeyBiryukov
8 months ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 34243:

Docs: Update the DocBlock for wp_page_menu() to include 'before', 'after', and 'walker' arguments added in [34200].

Align the $defaults array and include the default value for 'show_home'.

Props stevegrunwell.
Fixes #11095.

#11 @wonderboymusic
7 months ago

In 34653:

After [34200], force 'before' and 'after' to <ul> and </ul> when wp_nav_menu() falls back to wp_page_menu().

See #11095.

#12 @DrewAPicture
7 months ago

In 34654:

Tests: Add a test for the 'before' and 'after' arguments in wp_page_menu() when used as a fallback for wp_nav_menu().

When wp_page_menu() is used as a fallback for wp_nav_menu(), the before and after arguments should be set and output as <ul> and </ul>, respectively.

See #11095. See [34653].

#13 @obenland
5 months ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

[34243] broke back compat for themes adding a home link by checking ! isset( $args['show_home'] ), including Twenty Ten and Twenty Eleven.

I think we should leave the docs but remove the actual declaration in the default array for show_home.

This ticket was mentioned in Slack in #core by wonderboymusic. View the logs.


5 months ago

#15 @obenland
5 months ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 35737:

Template: Defining a default value for show_home breaks back compat.

To add a home link to the fallback menu output many themes only check if that
argument is set. Including Twenty Ten and Twenty Eleven. They check with
isset() so child themes and other instances using wp_page_menu() have a
chance to disable the home link by setting it to false.

Fixes #11095.

Note: See TracTickets for help on using tickets.