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've never posted here, but I'm tired of slapping code together. That said, I would be most appreciative if someone could help me with this.

I need a page template that:

  1. outputs the PARENT PAGEs,
  2. the CHILDREN PAGES of that PARENT PAGE,
  3. and finally output the titles and content of the GRANDCHILDREN PAGES so I can insert them into a tabbed layout.

Here's a diagram

The idea is that visitors should be able to get to the content on the GRANDCHILDREN PAGES in two clicks.

For the PARENT PAGES, I'm using wp_nav_menu.

For the CHILD PAGES, I'm using:

    <?php if ( is_page() ) { ?>
    <?php
    if($post->post_parent)
    $children = wp_list_pages('title_li=&child_of='.$post->post_parent.'&echo=0'); else
    $children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0');
    if ($children) { ?>

    <ul class="child-pages">
    <?php echo $children; ?>
    </ul>
    <?php } } ?>

And to output the GRANDCHILDREN PAGES title and content, I'm using some code from the codex:

GRANDCHILDREN PAGES

<ul class="nav nav-tabs" id="myTab">
<?php
$pages = get_pages('child_of='.$post->ID.'&sort_column=post_date&sort_order=desc');
$count = 0;
foreach($pages as $page)
{
    $content = $page->post_content;
    if(!$content)
        continue;
    if($count >= 100)
        break;
    $count++;
    $content = apply_filters('the_content', $content);
?>

<li>
<a data-toggle="tab" href="#<?php echo $count ?>"><?php echo $page->post_title ?></a>
</li>

<?php } ?>
</ul>

GRANDCHILDREN CONTENT

<div class="tab-content">

<?php
    $pages = get_pages('child_of='.$post->ID.'&sort_column=post_date&sort_order=desc');
    $count = 0;
    foreach($pages as $page)
    {
        $content = $page->post_content;
        if(!$content)
            continue;
        if($count >= 100)
            break;
        $count++;
        $content = apply_filters('the_content', $content);
    ?>


<div class="tab-pane" id="<?php echo $count ?>">
<?php echo $content ?>
</div>

<?php } ?>
</div>

I am certain there is a more efficient way to do without a gazillion loops and queries. Anyone have any ideas? I'm want to learn, and put code an elegant solution.

Thanks.

share|improve this question
    
I want only the child pages to show as tabbed content and the grand child pages to just show its thumbnails as links for its page Can you help me achieve this. –  user26983 Feb 4 '13 at 12:54
    
@Renu , are you the same person as user23213? If not, and you have a different question, please start your own question. –  s_ha_dum Feb 4 '13 at 20:05
add comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.