Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a bunch of pages and I only want to include 2 or 3 pages on my main menu. How would I do that? Currently my code looks like this:

wp_page_menu('include=156,572,542&sort_column=menu_order&echo=0');

If I am going to insert exclude=x pages, it wouldn't make sense because there's just too many of them.

Please no plugin recommendation. I've tried some but they conflict with other things I do in this regard.

UPDATE Here's the full function:

function main_nav() {?>
<div id="access">
    <div id="sub-access">
        <div id="sub-sub-access">   
            <div class="skip-link"><a href="#content">"><?php _e('Skip to content', 'thematic'); ?></a></div>
            <?php echo preg_replace('/<ul>/', '<ul class="sf-menu">', wp_page_menu('include=11,13,7,9,4&sort_column=menu_order&echo=0'), 1);?>
        </div>
     </div>   
</div><!-- #access --> <?php
}

add_action('thematic_header','main_nav',9);

It's a custom version of Thematic's thematic_access() function. I don't know why it's behaving this way. I tried it on a new installation, it doesn't work still.

share|improve this question
    
The code you have there should work. Are any of your pages nested? include will make the menu show only the pages you specify, and exclude will make the menu show all pages except the ones you specify. So you can't have both arguments. –  onetrickpony Dec 17 '10 at 16:40
    
None is nested. I really thought it wouldn't include pages other than the ones specified. Could it be the theme? Also I used exclude pages plugin prior to this, could it somehow affected wp? –  Joann Dec 17 '10 at 16:46
    
how are you calling this function? change echo to 1 if it's not used as a argument inside another function. better post the entire code here –  onetrickpony Dec 17 '10 at 17:00
add comment

3 Answers

up vote 1 down vote accepted

try

   ...
   echo preg_replace('/<ul>/', '<ul class="sf-menu">', 
       wp_page_menu(
         array(
          'include' => '11,13,7,9,4',
          'sort_column' => 'menu_order',
          'echo' => 0)), 1);

or

  ...
   echo preg_replace('/<ul>/', '<ul class="sf-menu">', 
       wp_page_menu(
         array(
          'include' => array(11,13,7,9,4),
          'sort_column' => 'menu_order',
          'echo' => 0)), 1);  

btw, there are better ways to add classes to html tags than using regexes like this...

share|improve this answer
add comment

The smarter way to do it would be to use WordPress 3.0's custom menus. replace wp_page_menu() with wp_nav_menu() and see how that works out for you.

share|improve this answer
add comment

This plugin claims to exclude pages from menus only, and provides a simple checkbox for excluding pages, perhaps it will help.
http://wordpress.org/extend/plugins/exclude-pages/

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.