WordPress.org

Ready to get started?Download WordPress

Forums

Displaying Child pages of the current page in post format is not working (3 posts)

  1. soppezzo
    Member
    Posted 1 year ago #

    Hi there!
    I´m trying to call this function on my page, since i want to show the sub-pages in post format, but it doesn´t seem to be working, it does nothing. Since I got this code from the Codex, I´m sure that the code is ok and I´m doing something wrong. The question is, should I call something else besides adding this to my page?

    <?php
    	$mypages = get_pages( array( 'child_of' => $post->ID, 'sort_column' => 'post_date', 'sort_order' => 'desc' ) );
    
    	foreach( $mypages as $page ) {
    		$content = $page->post_content;
    		if ( ! $content ) // Check for empty page
    			continue;
    
    		$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
    	}
    ?>

    Thanks a lot!!

  2. soppezzo
    Member
    Posted 1 year ago #

    Ok, I found this piece of code, which actually works! It is quite similar to the one I had above, but the other one didn´t work at all. So, Here I leave the right code below. What I need right now, is to show only the excerpt. Does anybody knows how to do this?

    <?php
    			 $mypages = get_pages('child_of='.$wp_query->post->ID.'&sort_column=post_date&sort_order=desc');
    			 $count = 0;
    			 foreach($mypages 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
    			 }
    			?>

    Thanks!

  3. vajnabotond
    Member
    Posted 8 months ago #

    I think by replaceing $content = $page->post_content; with: $content = $page->post_excerpt; :)

Topic Closed

This topic has been closed to new replies.

About this Topic