WordPress.org

Forums

[resolved] Sticky (non home) Page in Wp_Page_Menu? (5 posts)

  1. schaefermic
    Member
    Posted 5 years ago #

    Hello,

    I'm using Wp_Page_Menu to make a list of all the pages on my site, for a left navigation bar. The only problem is that I need one of the pages to be the first item listed, but not be the homepage.
    Currently I'm using this to sort by date, in descending order and excluding those 3 pages:

    <?php wp_page_menu( array( 'sort_column' => 'post_date', 'sort_order' => 'DESC', 'exclude' => '51,53,67' ) ); ?>

    Anyone have an idea how to do this?

    Thanks!

  2. vtxyzzy
    Member
    Posted 5 years ago #

    You can use 'echo' => 0 in the argument list and modify the menu like this:

    <?php
    $oldmenu = wp_page_menu(array('echo' => 0, 'sort_column' => 'DESC', 'exclude' => '51,53,67' ));
    echo str_replace('<ul>','<ul><li><a href="http://localhost/test/?p=39">First Item</a></li>',$oldmenu);
    ?>
  3. schaefermic
    Member
    Posted 5 years ago #

    ahhh, that seems like the right direction, but when i tried that it displayed nothing?

  4. vtxyzzy
    Member
    Posted 5 years ago #

    Sorry, somehow I left 'sort_column' as an arg. Please remove it.

    Also, in testing I found that I needed to limit the number of replacements to 1 using preg_replace. Please try this:

    <?php
    $oldmenu = wp_page_menu(array('echo' => 0, 'exclude' => '51,53,67' ));
    echo preg_replace('/<ul>/','<ul><li><a href="http://localhost/test/?p=39">First Item</a></li>',$oldmenu,1);
    ?>
  5. schaefermic
    Member
    Posted 5 years ago #

    ahhhh that did it!

    thanks so much! you've been very helpful!

Topic Closed

This topic has been closed to new replies.

About this Topic