If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!
A while back I had this problem. binary moon inspired me to solve the issue and I guess this is worth sharing amongst wordpress enthusiast. While creating any WordPress themes, designers generally hard code the main pages navigation to a few general pages like front pages or archives etc. The obvious reason for this is that you cant predict which pages are available with any WordPress blog.
Well actually you can. wp_list_pages() just does this and its no secret. But using wp_list_pages() with default options will list all the pages, and there may be a few pages that you may not want to include in the top navigational bar. One such example is the site map page that is created using a special site map template. In order to exclude the site map from man navigational links, you need to use wp_list_pages slightly differently.
wp-list_pages have a dozens of parameters. These parameters are used to control the appearance of the page list generated. Few of these parameters allow you to include or to exclude specific pages by IDs. But this does not solves the problem of a theme designer. Controlling the inclusion and exclusion based on IDs is not a good solution because in case of changes to the pages, the admin will have to edit the them pages and and change the code and must have knowledge of IDs. Most of the people running wordpress will have to contact their theme designers as they wouldn’t have skills to change their them.
The answer is to use Custom Fields for Pages. You can define custom fields for your posts and for your pages. While on Edit screen, you can see the option to add Custom Fields at the bottom. In Contents magic theme, I have added a custom field called ‘Navigation’ and set the value to ‘true’.
To have this working properly, the header of my theme list pages using
$PageOptions =array('title_li' => '','meta_key'=>'Navigation','meta_value'=>'true');
wp_list_pages($PageOptions);
And yes, most of the WordPress functions you can provide the arguments as an array just like above
Browse more posts marked in:
;


1 Ben // Jul 9, 2007 at 5:43 am
That’s an interesting idea. I wasn’t aware you could use the meta data in this way. Thanks for writing about this. It could be useful for me in the future.
2 Selvam // Oct 31, 2007 at 4:49 am
Simple and effective effort.
3 Jeremy // Feb 2, 2008 at 2:38 pm
Nicely done! I’m using it in a test site. Thanks.
4 Dave // Apr 17, 2008 at 2:11 pm
This works well!
How can I add a 2nd meta key / value to be included in the array?
Leave a Comment