WordPress.org

Ready to get started?Download WordPress

Forums

Loop to show child pages? (2 posts)

  1. MorayWeb
    Member
    Posted 5 years ago #

    Hi all, hoping someone can help me with that is probably really simple...

    ...I am still on the learning curve with developing wordpress themes!

    After searching forum posts and the docs/plugins etc for a while I was unable to find a way of running a loop on a parent page that shows child page information. I am developing a portfolio+blog site and would like to keep the two halves of the site seperate (rather than having a portfolio post category).

    As it stands just now I have a parent page called portfolio and child-pages for each client details page. I would like to create a loop to grab the title, and the content up to a <!--more--> tag.

    I will continue to dig through the docs and stuff, but hopefully one of helpful people in here can point me in the right direction! It's not that fancy, I wouldn't have thought a plugin would be required, is it?

    Regards,

    Gordon

  2. MorayWeb
    Member
    Posted 5 years ago #

    Progress update...

    I find a loop in the docs and butchered it slightly, I now have the following, but it is showing full posts(pages) rather than just up to the <!--more--> tag, and the links have the blog url inserted twice...

    <?php if (is_page('portfolio')){?>
    		<div class="post">
    			<?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 >= 2)
    		            break;
    		        $count++;
    		        $content = apply_filters('the_content', $content);
    		    ?>
    	        <h2><a href=\"<?php echo get_page_link($page->ID) ?>\"><?php echo $page->post_title ?></a></h2>
    	        <div class=\"entry\"><?php echo $content ?></div>
        		<?php }?>
    		</div>
    	<?php };?>

    Any ideas how I can polish this up a little??

Topic Closed

This topic has been closed to new replies.

About this Topic