• Technosailor.com
  • Desk of the Editor
  • Entrepreneurship
  • Web Marketing
  • Tech Policy
  • Contenido Español
Technosailor
  • Blog
  • Authors
  • Twitter Pitch Me!
  • Disclosures
  • Advertise on Technosailor.com
Apr
05
2007

WordPress FAQ: How Do I Use Child Pages More Effectively?

Posted by: Aaron Brazell
Woodlawn, MD, USA

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.

&lt;php
if( is_page() )
  {
  wp_list_pages('child_of=' . $wp_query->query_vars['page_id']);  	
  }
?&gt;

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

  1. WordPress FAQ: How Do I combine Blogs?
  2. WordPress FAQ: What’s up with the Amazon Plugin with WP 2.1.x?
  3. WordPress FAQ: How Do I Use Category Themes?
  4. WordPress FAQ: Where did my Preview Link Go?
  5. WordPress FAQ: How Do I Use Child Pages More Effectively?
  6. WordPress FAQ: How Do I Fix the Blogroll Category Issue in WordPress 2.1
  7. WordPress FAQ: How do I Move my blog to a new host?
  8. WordPress FAQ: User Roles Confusion
  9. WordPress FAQ: What is the best way to upgrade a WordPress 1.5 blog to WordPress 2.1?
  10. WordPress FAQ: Democracy Poll Feature
  11. WordPress FAQ: Benefits of Tagging
  12. WordPress FAQ: What’s the Best Way to Backup my Blog?
  13. WordPress FAQ: How Do I Integrate WordPress Into a Non-Blog Site?
  14. WordPress FAQ: Troubleshooting a WordPress Install
Previous in series Next in series
  • Add to Mixx!
  • Stumble it!
About the Author: Aaron Brazell is the lead editor of Technosailor.com and a social media expert. His passion is to see companies and individuals use the internet and web technologies wisely and effectively to promote their brands and companies. He served as Director of Technology at b5media from 2005-2008 and is currently an independent consultant.
Tagged: WordPress FAQ at 1:30 am -
discussion by DISQUS

Add New Comment

  • Subscribe:  This Thread
  • Go to:  My Comments ·  Community Page
  • Thanks. Your comment is awaiting approval by a moderator.

    Do you already have an account? Log in and claim this comment.

    discussion by DISQUS

    Add New Comment

    close Joe Chill(joechill)
    konvict

    status via twitter

    Murdering the Wayne parents, creating Batman · 2 minutes ago

    recent comments (follow comments)

      View Profile »
      Powered by Disqus · Learn more
      blog comments powered by Disqus
      • Recent Posts

        • Fantasy Football for Charity
        • Findability is a Legitimate Concern for Bloggers
        • Search and Findability
        • Will I See you in Boston? Or in San Francisco? Or in Boulder? Or in Vegas?
        • The Psychology of Gap Marketing
      • Recent Comments

        Powered by Disqus
      • Tags

        Aaron Brazell Advertising Apple b5media Blogging book conferences Design entrepreneurship Facebook Finance and Funding Google guest_blogging holidays humor hurricanes_and_natural_disasters interesting job Links Marketing Music nfl Op-Ed Perfect Pitch personal politics pr Predictions productivity Programming Security Social Issues Social Media Social Networking social_issues Sports Tech Industry Technology Technosailor Travel twitter unix Venture Files WordPress you_can_blog

      • License Creative Commons Attribution-Noncommercial-Share Alike 3.0 | Copyright © 2004 - 2008 - Aaron Brazell | Lisa helped out | Privacy Policy

        Twitter Pitch!

        <p>Twitter pitching is a form of pitch that requires succint "what does this mean for me" kind of pitching. It is the ultimate efficiency of words. You have 140 characters or less to tell me why your pitch matters to me or my readers. Please include a means of contacting you. This is included in your 140 characters. If you send successive pitches, you will likely be ignored, unless it's obvious that the first pitch was a case of "accidental send", etc.</p> <p>This form of pitching does not mean I'm being a diva. It means that my time is valuable, and you want a piece of it. It's good practice for you, and delivers your pitch in a format I want. Win-win.</p>


        (X) Close

        Twitter Pitch Me!