Hidden child pages on front page of site in new version of wordpress… any simple tutorial on making this happen or any plans on making this a function of wordpress in the future? It would really help wordpress have better functionality for those of us who also use it as a CMS.
<snip>
I know it’s more of a templating issue. By default most templates place all pages at the top or sidebar. Well, truth is for organization sake, this is not always good. I like to be able to link to these (which is simple enough) but only have them display that link on the parent page rather than the front page (meaning “front” of blog”). This would be a great “built-in” functionality, but right now it’s not there.
This question comes from William Lehman and is fairly involved. In fact, several exchanges occurred before I completely understood what William was driving at. In essence, the issue is that “Child Pages” - that is pages that have been assigned a Parent Page - display on all pages when using the template tag <a href="http://codex.wordpress.org/Template_Tags/wp_list_pages">wp_list_pages</a> and he wants to only list a child page if it is the parent page that the reader is on.
Complex, right?
Not so much with a little Template Grease™
Let me provide a little pseudo code. As templates are very individual things, where exactly this is placed is completely dependent on where you want your code to be displayed and in what form you want it to be displayed in.
<php
if( is_page() )
{
wp_list_pages('child_of=' . $wp_query->query_vars['page_id']);
}
?>
Okay, complex right? The bark is worse than the bite. First we do a little fact-checking. Are we on a page or not? This page load isn’t actually a feed? …Or an archive page? …or just a simple post? Right? Okay, then we move on.
Every page load in WordPress carries with it a set of query variables. No one ever sees these unless you go looking for them, but the query variables dictate how the page is loaded, if theres anything special that the rest of WordPress has to consider, such as categories or dates, or, if the page load is a page or a post. Having determined already that your page is actually a page and not a post, we can tap into the $wp_query object and extract the page ID from the query variables.
Having done this, we can pass this ID with it’s ubiquitous reference of $wp_query->query_vars['page_id'] to the wp_list_pages template tag using the “child_of” argument. This argument tells the page list creator that we only want to find the subpages of this particular page that we’re on.
And that’s it. Naturally, you can explore the deepr treasures of <a href="http://codex.wordpress.org/Template_Tags/wp_list_pages">wp_list_pages</a> and style your navigation/page list accordingly. That should get you going in the right direction though.
Readers are welcome to send their questions in to me and I’ll do my best to give them a spin.
Table of contents for WordPress FAQ
- WordPress FAQ: How Do I combine Blogs?
- WordPress FAQ: What’s up with the Amazon Plugin with WP 2.1.x?
- WordPress FAQ: How Do I Use Category Themes?
- WordPress FAQ: Where did my Preview Link Go?
- WordPress FAQ: How Do I Use Child Pages More Effectively?
- WordPress FAQ: How Do I Fix the Blogroll Category Issue in WordPress 2.1
- WordPress FAQ: How do I Move my blog to a new host?
- WordPress FAQ: User Roles Confusion
- WordPress FAQ: What is the best way to upgrade a WordPress 1.5 blog to WordPress 2.1?
- WordPress FAQ: Democracy Poll Feature
- WordPress FAQ: Benefits of Tagging
- WordPress FAQ: What’s the Best Way to Backup my Blog?
- WordPress FAQ: How Do I Integrate WordPress Into a Non-Blog Site?
- WordPress FAQ: Troubleshooting a WordPress Install


Add New Comment
Thanks. Your comment is awaiting approval by a moderator.
Do you already have an account? Log in and claim this comment.
Add New Comment