Support » Fixing WordPress » Nav menu order.

  • edwardgyngell

    (@edwardgyngell)


    Hello. I am having trouble trying to arrange my menu list in a specific order.

    I would like it to display in the order below with an em dash in the middle to separate them:

    Projects — Information — News

    How can I do this?

    This is the code I have.

    &mdash; <?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); ?> &mdash;
    <a href="#" class="show_hide">Information</a>

    My website is http://edwardgyngell.com

    Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • Keith Burgie

    (@keith-burgie)

    Have you tried setting the page order within the admin?

    http://en.support.wordpress.com/pages/page-attributes/

    David Gard

    (@duck_boy)

    You’d need to set your page order, and then you can output them as you desire using this (untested) code –

    <?php
    /** Get the pages */
    $pages = get_pages();
    
    /** Construct a link for each of the pages in $links */
    foreach($pages as $page) :
    
    	/** Make the menu item */
    	$page_link = sprintf("\n\t".'<li class="page-%1$s">'."\n", is_page($page->ID) ? 'active' : 'item');
    
    	/** Make the link */
    	$page_link.= sprintf("\t\t".'<a href="%1$s" title="%2$s">%3$s</a>'."\n", get_page_link($page->ID), attribute_escape(apply_filters('the_title', $page->post_title)), apply_filters('the_title', $page->post_title));
    
    	$page_link.= "\t".'</li>'."\n");
    
    	/** Add the menu item with link that we just created to an array */
    	$links[] = $page_link;
    
    endforeach;
    
    /** Create the information link */
    $links[] = '"\n\t".<a href="#" class="show_hide">Information</a>'."\n";
    
    /** Output everything, seperated by the '&mdash;' that is desired */
    printf('%1$s', explode('&mdash;', $links));
    ?>
    edwardgyngell

    (@edwardgyngell)

    Thanks heaps for the replies. Yes I have set the intended order.

    The code above is creating an error. It doesn’t like the 2nd line in the making a link section.

    David Gard

    (@duck_boy)

    It’s probably just a typo that I made. What is the error that you are getting?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Nav menu order.’ is closed to new replies.