Code to display links from tags is messing comments up (1 post)

  1. f1f
    Posted 7 years ago #

    I'm using a piece of code to display the latest 10 posts from a certain tag in a post:

     global $post;
     $myposts = get_posts('numberposts=10&tag=tagname');
     foreach($myposts as $post) :
        <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
     <?php endforeach; ?>

    When I use it in a page it works fine and correctly displays the latest ten posts with the relevant tag.

    But when I use it in a post although it correctly displays the latest posts it also interferes with the comments that are displayed below the post: it displays the comments from the last post described in the list.

    I can't work out what I've done wrong with the code - can anyone help please?

    I'm using the Exec PHP plugin to execute PHP code in posts.

Topic Closed

This topic has been closed to new replies.

About this Topic