0

I start learning Wordpress from scratch then i decided to put the 5 latest post in sidebar, and the code is alright and when i decided to add description using excerpt, excerpt desplay same text can someone guide me what should i do, what should i improve,

any idea is appreciated thank's in advance!

thumbnail with excerpt

here is my current code:

    <ul class="lalest">
<?php
$IDOutsideLoop = $post->ID;
global $post;

$myposts = get_posts('showposts=5');
foreach($myposts as $post) :
?>
    <li>
    <div class="thumb">
      <?php echo get_the_post_thumbnail($page->ID, 'thumbnail'); ?>
    </div>
    <a href="<?php the_permalink(); ?>">
      <?php the_title(); ?>
      </a>
             <?php the_excerpt(); ?>

      </li>
    <?php endforeach; ?>
  </ul>
3

You need to be using setup_postdata($post); as in all of the examples for get_posts. You need:

$myposts = get_posts('numberposts=5');
foreach($myposts as $post) :
    setup_postdata($post);
    // the rest of your function

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.