• Resolved schaefermic

    (@schaefermic)


    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!

Viewing 4 replies - 1 through 4 (of 4 total)
  • 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="https://localhost/test/?p=39">First Item</a></li>',$oldmenu);
    ?>
    Thread Starter schaefermic

    (@schaefermic)

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

    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="https://localhost/test/?p=39">First Item</a></li>',$oldmenu,1);
    ?>
    Thread Starter schaefermic

    (@schaefermic)

    ahhhh that did it!

    thanks so much! you’ve been very helpful!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Sticky (non home) Page in Wp_Page_Menu?’ is closed to new replies.