Results 1 to 10 of 10
Feb 3, 2009, 12:06 #1
Wordpress Question how to limit pages shown in the menu
Sorry if this is in the wrong area, but the Wordpress Forums aren't very responsive:
Does anyone know how to limit the amount of pages that show up in the menu in Wordpress:
and only list 5 pages in the menu instead of all of them?
Feb 3, 2009, 12:33 #2
- Join Date
- Jul 2005
- West Springfield, Massachusetts
- 198 Post(s)
- 3 Thread(s)
The wp_list_pages function is in the wp-includes/post-template.php file. It has these default arguments
$defaults = array(
'depth' => 0, 'show_date' => '',
'date_format' => get_option('date_format'),
'child_of' => 0, 'exclude' => '',
'title_li' => __('Pages'), 'echo' => 1,
'authors' => '', 'sort_column' => 'menu_order, post_title',
'link_before' => '', 'link_after' => ''
Or you could explicitly exclude certain pages. http://codex.wordpress.org/Template_Tags/wp_list_pagesBig Change Coming Soon - if you want your PMs save them now!
What you need to do to prepare for our migration to Discourse
A New SitePoint Forum Experience: Our Move to Discourse
Feb 3, 2009, 14:05 #3
the Depth attribute didn't work it still lists all the pages.
Feb 3, 2009, 16:28 #4
You could parse the HTML produced by wp_list_pages and extract only however many items you need.Salathe
Software Developer and PHP Manual Author.
Feb 3, 2009, 16:42 #5
that's a good idea, the only problem with that is whenever I call the wp_list_pages() it generates the HTML live. Even if I assign it to a variable.
would generate the HTML and display it at the same time.
hope that makes sense.
Feb 3, 2009, 17:44 #6
- Join Date
- May 2006
- 0 Post(s)
- 0 Thread(s)
if ( $r['echo'] )
Feb 3, 2009, 19:24 #7Or you could explicitly exclude certain pages. http://codex.wordpress.org/Template_Tags/wp_list_pagesCode PHP:
Feb 3, 2009, 19:26 #8
hmm, yeah your right, that fixed the problem but caused another, I was able to parse the string and everything but for some reason using the echo 0 parameter caused all of the regular content items in my page only display one character, you can see it here:
I used this code:
$howmany = 4;
$pages = wp_list_pages("title_li=&sort_column=menu_order&echo=0");
$pages_arr = explode("\n", $pages);
the pages that I want to limit are on the top, all the pages are on the left.
Any ideas, or does anyone know an easier way?
Feb 3, 2009, 19:33 #9
Feb 3, 2009, 19:59 #10
That would work if it was only me that was working on the site, however i'm making this with a Wordpress newbie in mind so at the beginning they'd only have one page and then they would add more and more so there is no way of knowing which page id's i'd need to exclude or include.