WordPress.org

Ready to get started?Download WordPress

Forums

Nav menu order. (5 posts)

  1. edwardgyngell
    Member
    Posted 1 year ago #

    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

  2. Keith Burgie
    Member
    Posted 1 year ago #

    Have you tried setting the page order within the admin?

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

  3. David Gard
    Member
    Posted 1 year ago #

    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));
    ?>
  4. edwardgyngell
    Member
    Posted 1 year ago #

    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.

  5. David Gard
    Member
    Posted 1 year ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.