• Hey everyone, I’m not a big php coder so I need to come here and ask this question.

    Basically I’m using WP for my portfolio site, and all my projects have 3 levels. There is a Grandparent (Example: Webpage Design), a Parent which sort of acts like a category (Example: “Landing Page Designs”), and then a Grandchild page which acts as an information page about that project.

    Now I’ve been told many times by my friend I should just uses posts to do all of this stuff but I would really like to stick to pages so I can separate my blog and my site content.

    What I’m trying to do is create a template for the Grandparent page, which would be able to identify all of it’s Children, and output a formatted unordered list (which I could add classes to) of all it’s Grandchildren. Then break and redo that process for every Parent page.

    Right now I can easily use get_pages to display thumbnails of all the grandchildren and children pages that have content. The problem is I have no way to identify just a parent and use it as say a H2, and then break the format for the next parent. Is there any sort of for statement I could use to accomplish this?

    This is the code I use to get all the grandchildren how I want. (I have the line about count == 4 because I need to apply a different class to the fourth thumbnail for my layout. The counting only to 9 is not important.)

    <ul class="thumblist">
    			<?php
    
    				$pages = get_pages('child_of='.$post->ID.'');
    			;
    				$count = 0;
    				foreach($pages as $pagg)
    				{
    					$content = $pagg->post_content;
    					if(!$content)
    						continue;
    					if($count >= 9)
    						break;
    					$count++;
    				?>
    
    					<li <?php if( $count == 4 ) { echo 'class="thumbodd"'; } ?>><a href="<?php echo get_page_link($pagg->ID) ?>"><img src="<?php echo get_post_meta($pagg->ID, 'thumb', true); ?>" alt="<?php echo $pagg->post_title ?>"/></a></li>
    
    			<?php }	?>
    
    		</ul>

    Since I really don’t do PHP I really could use help with this. Thank you very much in advanced and I can answer any questions you have about trying to make this work. Thanks again!

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Using 3 levels of get_pages and displaying everything on the Grandparent page’ is closed to new replies.