WordPress.org

Ready to get started?Download WordPress

Forums

displaying date and excerpt with wp_get_recent_posts ? (3 posts)

  1. marenm
    Member
    Posted 3 years ago #

    Hi there,

    I'm using the wp_get_recent_posts to add a custom recent posts thing to my child theme.
    I've got the title/permalink showing up but can't get the date or the excerpt. Is this even possible with wp_get_recent_posts?

    If someone could steer me in the right direction that would be much appreciated.

    thanks!

  2. fishfinder
    Member
    Posted 3 years ago #

    Try this:

    <?php
     $postslist = get_posts('numberposts=3&order=DESC&orderby=date');
     foreach ($postslist as $post) :
        setup_postdata($post);
     ?>
     <div class="entry">
     <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
     <?php the_time(get_option('date_format')) ?>
     <?php the_excerpt(); ?>
     </div>
     <?php endforeach; ?>
  3. marenm
    Member
    Posted 3 years ago #

    Thanks! That did work, at least most of the way.
    However, instead of the post title, for some it just displays "Home."
    Very strange. Any thoughts?
    Here is my code (almost identical)

    //Call Recent Posts
    		function recentpostcycle() { ?>
    			<div class="cycleNewsPosts">
    				<ul>
    					<?php
    					$args = array( 'numberposts' => 10, 'order' => 'ASC', 'category_name' => 'news');
    					 $postslist = get_posts( $args);
    					 foreach ($postslist as $post) :
    					    setup_postdata($post);
    					 ?>
    					 <li class="entry">
    					 <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
    					 <?php the_time(get_option('date_format')) ?>
    					 <?php the_excerpt(); ?>
    					 </li>
    					 <?php endforeach; ?>
    				</ul>
    			</div>

Topic Closed

This topic has been closed to new replies.

About this Topic