+ Reply to Thread
Results 1 to 10 of 10

Thread: Adding a delimiter between menu itemes

  1. #1
    Mild Fuzz is offline Here For The Peanuts
    Join Date
    Feb 2010
    Posts
    103

    Default Adding a delimiter between menu itemes

    Using wp_list_pages() to create a menu, I am sure there should be an easy way to add a pipe ( '|' ) between pages, can't seem to find any info it.

    Cheers

  2. #2
    chipbennett's Avatar
    chipbennett is online now WordPress Legend
    Join Date
    Feb 2009
    Location
    St. Louis, MO
    Posts
    1,718

    Default

    Quote Originally Posted by Mild Fuzz View Post
    Using wp_list_pages() to create a menu, I am sure there should be an easy way to add a pipe ( '|' ) between pages, can't seem to find any info it.

    Cheers
    wp_list_pages() returns results wrapped inside LI tags.

    There's no way to tell the function to put any text between list items. But, you can very easily use CSS to style both the list (UL) and the list items (LI).

    By default, the function wraps everything in a UL class="pagenav", and assigns class="page-item" to each of the LIs.

    So, you could approximate a pipe between list items by styling the right/left border property for LI.page-item.

    See here for more information.
    WP TurnKey - Turn-Key WordPress installation and maintenance services
    WordPress user since 2005 | @chip_bennett | chipbennett.net | cbnet Plugins

  3. #3
    Mild Fuzz is offline Here For The Peanuts
    Join Date
    Feb 2010
    Posts
    103

    Default

    Quote Originally Posted by chipbennett View Post

    So, you could approximate a pipe between list items by styling the right/left border property for LI.page-item.

    That's what I am doing, but I thought should such functionality exist, it would be useful to know.

    It seems to me that such an argument would be a welcome addition to wp_list_pages

  4. #4
    chipbennett's Avatar
    chipbennett is online now WordPress Legend
    Join Date
    Feb 2009
    Location
    St. Louis, MO
    Posts
    1,718

    Default

    Quote Originally Posted by Mild Fuzz View Post
    That's what I am doing, but I thought should such functionality exist, it would be useful to know.

    It seems to me that such an argument would be a welcome addition to wp_list_pages
    Perhaps, but only if the function returned something other than an unordered list, wrapped in LI tags. As it is, putting something between the closing LI tag of one list item and the opening LI tag of the next list item wouldn't be valid HTML.

    You could use the text_before or text_after parameters, but they place text inside the link (A) tags, and I'm sure that wouldn't be what you're after.
    WP TurnKey - Turn-Key WordPress installation and maintenance services
    WordPress user since 2005 | @chip_bennett | chipbennett.net | cbnet Plugins

  5. #5
    Mild Fuzz is offline Here For The Peanuts
    Join Date
    Feb 2010
    Posts
    103

    Default

    Quote Originally Posted by chipbennett View Post
    Perhaps, but only if the function returned something other than an unordered list, wrapped in LI tags. As it is, putting something between the closing LI tag of one list item and the opening LI tag of the next list item wouldn't be valid HTML.

    You could use the text_before or text_after parameters, but they place text inside the link (A) tags, and I'm sure that wouldn't be what you're after.
    As you code the corresponding <ul> tags seperately, it would logical to make the <li> tags optional also?

  6. #6
    chipbennett's Avatar
    chipbennett is online now WordPress Legend
    Join Date
    Feb 2009
    Location
    St. Louis, MO
    Posts
    1,718

    Default

    Quote Originally Posted by Mild Fuzz View Post
    As you code the corresponding <ul> tags seperately, it would logical to make the <li> tags optional also?
    Well, it is called wp_list_pages() for a reason. :)
    WP TurnKey - Turn-Key WordPress installation and maintenance services
    WordPress user since 2005 | @chip_bennett | chipbennett.net | cbnet Plugins

  7. #7
    Ryan's Avatar
    Ryan is offline WPTavern Forum Moderator
    Join Date
    Jan 2009
    Location
    New Zealand
    Posts
    2,418

    Default

    You can filter the wp_list_pages() function, so you could replace those <li> tags with anything you want.

    The following should (unless I screwed something up - which is highly likely) replace the wp_list_pages() function with a string of text:
    Code:
    <?php
    function random_filter() {
    	$newlist= 'I replaced the wp_list_pages() function with this random bit of text';
    	return $newlist;
    }
     
    add_filter( 'wp_list_pages', 'random_filter' );
    ?>
    

  8. #8
    Ryan's Avatar
    Ryan is offline WPTavern Forum Moderator
    Join Date
    Jan 2009
    Location
    New Zealand
    Posts
    2,418

    Default

    The example I gave above isn't quite so useful to what you are doing. The following might be more useful since it should make use of the existing data:
    Code:
    <?php
    function random_filter( $args ) {
    	$args = $args . 'I add this to the regular list';
    	return $args;
    }
     
    add_filter( 'wp_list_pages', 'random_filter' );
    ?>
    
    I don't need filters very often (at all?) so it's entirely possible these don't work. If they don't work, just lemme and I'll figure out how they should work.

  9. #9
    Ryan's Avatar
    Ryan is offline WPTavern Forum Moderator
    Join Date
    Jan 2009
    Location
    New Zealand
    Posts
    2,418

    Default

    Sorry for the triple post ...

    To achieve the effect you are looking for, I usually apply a right hand border to the links. This gives the visual effect without having to modify the markup. It's rare that you would ever want anything but a list for a list of pages anyway. I use the last-child pseudo class to prevent it from displaying on the last list item, this obviously doesn't work in some browsers, but I don't worry about that these days since it's not exactly a mission critical part of the site.

  10. #10
    Otto's Avatar
    Otto is offline Trac Master
    Join Date
    Apr 2009
    Location
    Memphis, TN
    Posts
    770

    Default

    It'd probably be simpler to just write your own code.

    1. Call get_pages to get a list of pages.
    2. Go through those pages with a foreach, and build the links to each page. Put them in an array.
    3. Use implode to turn that array into a string with your delimiters.

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts