Make WordPress Core

Opened 17 years ago

Closed 11 years ago

#11095 closed enhancement (fixed)

Format wp_list_pages and wp_page_menu without <li> tags

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

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 12 years ago.
Adds 'format', 'before', and 'after' arguments to wp_list_pages()
11095.2.patch​ (1.1 KB ) - added by stevegrunwell 11 years ago.
Adds inline docs to code committed by @wonderboymusic in 34200

Download all attachments as: .zip

Change History (17)

#1 @miqrogroove
17 years ago

  • Component General → Template
  • Keywords wp_list_pages wp_page_menu removed
  • Type defect (bug) → feature request

#2 @nacin
17 years ago

  • Milestone Unassigned → Future Release

#3 @nacin
13 years ago

  • Component Template → Posts, Post Types
  • Focuses template added

@stevegrunwell
12 years ago

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

#4 @stevegrunwell
12 years 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
11 years ago

  • Keywords needs-patch added; has-patch removed
  • Milestone Future Release → 4.4
  • Type feature request → 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
11 years ago

  • Owner set to wonderboymusic
  • Resolution → fixed
  • Status new → closed

In 34200:

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

Fixes #11095.

#7 @DrewAPicture
11 years ago

  • Keywords needs-docs added
  • Resolution fixed
  • Status closed → reopened

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

@stevegrunwell
11 years ago

Adds inline docs to code committed by @wonderboymusic in 34200

#8 @stevegrunwell
11 years ago

  • Keywords needs-patch needs-docs removed

#9 @DrewAPicture
11 years ago

  • Keywords has-patch added

#10 @SergeyBiryukov
11 years ago

  • Resolution → fixed
  • Status reopened → 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
11 years 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
11 years 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
11 years ago

  • Resolution fixed
  • Status closed → 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.


11 years ago

#15 @obenland
11 years ago

  • Resolution → fixed
  • Status reopened → 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.