• So I’m trying to create a loop that puts all of the child and grandchild pages on the one parent page. My problem is that I also need to differentiate which is a child of the main page and which is a grandchild, so i can apply differently styled titles to them. here is the code I have now, but it’s not doing it for me

    <?php the_content(); ?>
    			<?php
    				$ancestors = count(get_post_ancestors($post->ID));
    				$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;
    					$count++;
    					$content = apply_filters('the_content', $content);
    					$children = is_tree($page);
    					$parents = count(get_children());
    					 {
    
    					if($children > 1) {
    				?>
    					<h2><a href="<?php echo get_page_link($page->ID) ?>"><?php echo $page->post_title ?></a></h2>
    					<p><?php echo $parents ?></p>
    					<p><?php echo $children ?></p>
    
    					<?php echo $content ?>
    
    					<?php } else { ?>
    					<h3><a href="<?php echo get_page_link($page->ID) ?>"><?php echo $page->post_title ?></a></h3>
    					<p><?php echo $parents ?></p>
    					<p><?php echo $children ?></p>
    					<?php echo $content ?>
    
    				<?php } } }?>
  • The topic ‘Display the child pages and grandchild pages on the parent page in separate divs’ is closed to new replies.