Home Forum Advertise Contact Me About WPTavern WPWeekly Show Info

Go Back   WordPress Tavern Forum » WordPress » Troubleshooting

Troubleshooting Need help with WordPress? Post here

Reply
 
Share LinkBack Thread Tools Display Modes
  post #1 (permalink)  
Old 02-03-2010, 08:58 AM
Hello World
 
About
Join Date: Feb 2010
Posts: 60
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
Reply With Quote
  post #2 (permalink)  
Old 02-03-2010, 09:07 AM
chipbennett's Avatar
WordPress Rockstar
 
About
Join Date: Feb 2009
Location: St. Louis, MO
Posts: 1,017
Send a message via ICQ to chipbennett Send a message via AIM to chipbennett Send a message via MSN to chipbennett Send a message via Yahoo to chipbennett Send a message via Skype™ to chipbennett
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.

@chip_bennett | chipbennett.net (est. 2000) | WordPress user since May, 2005 | Linux (Kubuntu) user since September, 2007
cbnet Plugins
Reply With Quote
  post #3 (permalink)  
Old 02-03-2010, 09:15 AM
Hello World
 
About
Join Date: Feb 2010
Posts: 60
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
Reply With Quote
  post #4 (permalink)  
Old 02-03-2010, 09:20 AM
chipbennett's Avatar
WordPress Rockstar
 
About
Join Date: Feb 2009
Location: St. Louis, MO
Posts: 1,017
Send a message via ICQ to chipbennett Send a message via AIM to chipbennett Send a message via MSN to chipbennett Send a message via Yahoo to chipbennett Send a message via Skype™ to chipbennett
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.

@chip_bennett | chipbennett.net (est. 2000) | WordPress user since May, 2005 | Linux (Kubuntu) user since September, 2007
cbnet Plugins
Reply With Quote
  post #5 (permalink)  
Old 02-03-2010, 09:46 AM
Hello World
 
About
Join Date: Feb 2010
Posts: 60
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?
Reply With Quote
  post #6 (permalink)  
Old 02-03-2010, 10:01 AM
chipbennett's Avatar
WordPress Rockstar
 
About
Join Date: Feb 2009
Location: St. Louis, MO
Posts: 1,017
Send a message via ICQ to chipbennett Send a message via AIM to chipbennett Send a message via MSN to chipbennett Send a message via Yahoo to chipbennett Send a message via Skype™ to chipbennett
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. :)

@chip_bennett | chipbennett.net (est. 2000) | WordPress user since May, 2005 | Linux (Kubuntu) user since September, 2007
cbnet Plugins
Reply With Quote
  post #7 (permalink)  
Old 02-03-2010, 02:31 PM
Ryan's Avatar
WPTavern Forum Moderator
 
About
Join Date: Jan 2009
Location: New Zealand
Posts: 1,782
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' );
?>
Reply With Quote
  post #8 (permalink)  
Old 02-03-2010, 02:34 PM
Ryan's Avatar
WPTavern Forum Moderator
 
About
Join Date: Jan 2009
Location: New Zealand
Posts: 1,782
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.
Reply With Quote
  post #9 (permalink)  
Old 02-03-2010, 02:44 PM
Ryan's Avatar
WPTavern Forum Moderator
 
About
Join Date: Jan 2009
Location: New Zealand
Posts: 1,782
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.
Reply With Quote
Old 02-03-2010, 02:51 PM
Otto's Avatar
Kegger
 
About
Join Date: Apr 2009
Location: Memphis, TN
Posts: 518
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 With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 01:42 PM.