• Resolved Lindquist

    (@lindquist)


    Alright, I have found a couple websites (and topics) that tackle similar situations, but none of them have worked out for what I’m trying to accomplish.

    I am using WordPress as a CMS and I have an About page that needs several sub pages. I’ve used the CSS to make each subpage have it’s own <div> that is floated to make columns. The result is three columns of content with the title (as a permalink) and the content (or “excerpt” using “more” in the editor).

    I was able to accomplish what I need using posts and categories using the following code:

    <?php query_posts('order=asc&cat=3&showposts='.get_option('posts_per_page')); ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <div class="secondary-section">
    <h2><a href="<?php the_permalink(); ?>" title="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    <?php the_content('(Read more &hellip;)'); ?>
    </div>
    <?php endwhile; else: ?>
    <?php endif; ?>

    What I need is to accomplish the same effect, except the posts are child pages and the category is the parent page.

    Please notice that I have the posts listed from the first published with the newest on the bottom. I’d like to do the same with pages.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Lindquist

    (@lindquist)

    I did more digging. I found something that seems to work for the most part:

    https://codex.www.ads-software.com/Function_Reference/get_pages#Displaying_Child_pages_of_the_current_page_in_post_format

    <?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
    	}
    ?>

    I was able to replace the content on there with my <div> structure and the posts now show up. However, I have not figured out how to show only the “excerpt” with the more link at the end.

    I’ll continue playing to try and find a solution, but any help would be greatly appreciated. Thanks.

    Did you find the answer to this question? I’m having the same issue.
    Thanks

    Hey guys,

    There was some little issue with this code, i have tried to use it too but i was getting the content of the current page under each child title, eventually i have changed only the
    <?php echo $content ?>
    to
    <?php echo $page->post_content ?>

    not the smartest solution, but works for me very well(my php skills are pretty low).

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Display Child Pages (title & content) on Parent Page’ is closed to new replies.