Forums

[resolved] Sidebar Loop Shows Page Excerpt (3 posts)

  1. zOmbiesundaYs
    Member
    Posted 2 years ago #

    I'm working on a theme that has a sidebar that shows the title, date and excerpt of the latest posts.

    The title and dates are shown properly, however the excerpt instead shows the current page excerpt instead.

    For example, viewing the homepage, each excerpt is instead the first bit of the homepage instead of each post.

    The code is:

    <ul>
    			<?php
    			global $post;
    			$myposts = get_posts('numberposts=3');
    			foreach($myposts as $post) :
    			?>
    
    <li><a>" title="<?php the_title(); ?>"><?php the_title(); ?></a><?php the_time('F jS, Y') ?><div class="sidebar-excerpt"><?php the_excerpt() ?></div></li>
    			<?php endforeach; ?>
    			</ul>

    The site is eurofx.thefra.me

    Any help would be most appreciated. Thanks!

  2. stvwlf
    Member
    Posted 2 years ago #

    you need to add a line of code, per codex page
    http://codex.wordpress.org/Template_Tags/get_posts

    .....
    foreach($myposts as $post) :
    ADD THIS LINE ---->   setup_postdata($post); ?>
       <li><a>" title="<?php the_title(); ?>"><?php the_title(); ?></a><?php the_time('F jS, Y') ?><div class="sidebar-excerpt"><?php the_excerpt() ?></div></li>
    ......
  3. zOmbiesundaYs
    Member
    Posted 2 years ago #

    I went over that codex page 3 or 4 times, and somehow overlooked that little line.

    Worked, thanks so much!

Topic Closed

This topic has been closed to new replies.

About this Topic