WordPress.org

Ready to get started?Download WordPress

Forums

Latest comments link to the article it came from (6 posts)

  1. denzel2364
    Member
    Posted 4 years ago #

    Hi there,

    I have a piece of code below tht displays latest comments. However, when i click on the link it takes me to 'site.com/blog/archives/1' for all the links even though they are from different sources.

    Any ideas where im going wrong?

    <?php
    $comments = get_comments('status=approve&number=5');
      foreach($comments as $comm) :?>
        <a href="<?php the_permalink(); ?>" title=xx"><?php echo($comm->comment_content);?></a>
      <?php endforeach;?>
    </div>
  2. denzel2364
    Member
    Posted 4 years ago #

    version: 2.8

  3. Mike Little
    Member
    Posted 4 years ago #

    I think you may need to use something like echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) instead of the_permalink()

    Mike

  4. denzel2364
    Member
    Posted 4 years ago #

    How would that work with the above code?

  5. denzel2364
    Member
    Posted 4 years ago #

  6. Mike Little
    Member
    Posted 4 years ago #

    If you still haven't solved this, try this code:

    <?php
    $comments = get_comments('status=approve&number=5');
      foreach($comments as $comm) :?>
        <a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ); ?>" title=xx"><?php echo($comm->comment_content);?></a>
      <?php endforeach;?>
    </div>

    Mike

Topic Closed

This topic has been closed to new replies.

About this Topic