• I’ve been searching around but I couldn’t find an answer to this question, although I’m pretty confident that it’s not an especially difficult problem.

    Currently, my menu displays like this:
    HOME ABOUT ME BLOG POLICY BOOK REVIEWS

    I would like to add “\\” characters between the pages, like this:
    HOME \\ ABOUT ME \\ BLOG POLICY \\ BOOK REVIEWS

    I’ve found a few topics for adding the pipe character using CSS, but that’s really not what I’m looking to do.

    How can I tell WP_LIST_PAGES to add “\\” between each page?

Viewing 15 replies - 1 through 15 (of 20 total)
  • This will work…

    <?php $new = ' \\\\ '; wp_list_pages('link_before=<li>&link_after='.$new.'</li>');?>

    You can then change $new to be whatever you like, you need 4 slashes to have 2 display due to how PHP reads them..

    Post back if you get stuck..

    Thread Starter bpetruzzo

    (@bpetruzzo)

    Thanks for the help.

    It works except now it adds “pages” before everything else, which is not a link. It seems that it’s a title or something, which I’m not sure where it’s coming from.

    How can I keep the title from showing up?

    Add in a blank title_li= to get rid of the Pages heading. This will also prevent the surrounding ul tags from being created so you’ll end up with something like this:

    <ul><?php $new = ' \\\\ '; wp_list_pages('title_li=&link_before=<li>&link_after='.$new.'</li>');?></ul>

    Thread Starter bpetruzzo

    (@bpetruzzo)

    That worked perfectly! Thank you very much!

    The following snippet in your template will output the desired effect:

    <?php
    $links = get_pages();
    
    foreach($links as $i => $page)
    	$links[$i] = '<li class="page-' . (is_page($page->ID) ? 'active' : 'item') . '"><a href="' . get_page_link($page->ID) . '" title="' . attribute_escape(apply_filters('the_title', $page->post_title)) . '">' . apply_filters('the_title', $page->post_title) . '</a></li>';
    
    echo implode(' | ', $links);
    ?>

    capn code-

    your solution works great for what i need! thanks!

    wondering if there is any way to control the order or visibility of any of the links — similar to how wp_list_pages() does?

    example of how wp_list_pages() does it:
    wp_list_pages(‘sort_column=menu_order&include=2,4,34,37&title_li=’);

    thank you very much!

    andrew

    nevermind — i figured it out!!

    great advice — thanks again!

    andrew

    Glad it worked out for you, Andrew.

    You can add a link to the index by adding the following:

    array_unshift($links, '<li class="page-item"><a href="' . get_option('home') . '" title="Home"> Home </a>');

    before:

    implode(' | ', $links);

    Hello Capn Code.

    I am using your script and it works great. I am just having one problem. My last menu item does not get assigned the class of page-active when pressed.

    If you could offer any solutions that would be great.

    Cor blimey! Thanks for pointing out that oversight, eassae. This will do the trick:

    array_unshift($links, '<li class="page-'. (is_front_page() ? 'active' : 'item') .'"><a href="' . get_option('home') . '" title="Home">Home</a>');

    @capn Code

    How could I edit this PHP to be used with the “wp_list_bookmarks” function? I’d like to list the links and throw a ” | ” between each one.

    This is what I’ve tried so far. It will list the bookmarks correctly, but for some reason doesn’t insert the ” | ” between them:

    <?php $links = wp_list_bookmarks('title_li=&categorize=0&sort_column=menu_order');
    								  foreach($links as $i => $page)
    								  $links[$i] = '<li><a href="' . link_url($page->ID) . '" title="' . attribute_escape(apply_filters('link_name', $page->link_name)) . '">' . apply_filters('link_name', $page->link_name) . '</a></li>';
    
    								  echo implode('<span class="divider"> | </span>', $links); ?>

    Thanks for the help.

    dpcalhoun,

    This should do the trick:

    $links = wp_list_bookmarks('title_li=&categorize=0&sort_column=menu_order&echo=0');
    $bookmarks = explode('</li>', $links); //create array from string returned by wp_list_bookmarks
    array_pop($bookmarks); //pop last element off array
    echo implode('<span class="divider"> | </span>', $bookmarks);

    @capn Code

    Thank you so much! I’ve been trying to figure this out from your first code for awhile. I’m still a PHP novice. Slowly learning. ??

Viewing 15 replies - 1 through 15 (of 20 total)
  • The topic ‘Adding special characters between menu items using WP_LIST_PAGES’ is closed to new replies.