Grow your CSS skills. Land your dream job.

[Solved] WordPress – related posts and comments messing up

  • # July 10, 2009 at 8:27 am

    Hi everyone,

    Back when I was still using WP 2.6 or 2.7, I hacked it up (used some PHP I found on the web instead of using a plugin) to display related posts. Anyway, it’s been a while and I forgot exactly what I had done (I don’t really know PHP), but I just realized that my WordPress posts are now displaying the comments from the last RELATED POST, not the post you are viewing. Here’s an example:

    http://expatintaiwan.net/2009/06/28/tra … to-taiwan/

    You’ll see there are 5 related posts. The last one is "English speakers have it easy." The comments are then displayed. Only the comments are for the related post, "English speakers have it easy," not for the Transformers post.

    I’ve got the section I think is responsible for the related posts and also the section for the comments, but I’m not sure. If I need to post more, please let me know. I’d appreciate some help in getting this figured out.

    Code:
    //for use in the loop, list 5 post titles related to first tag on current post
    $tags = wp_get_post_tags($post->ID);
    if ($tags) {
    echo ‘Related Posts:’;
    $first_tag = $tags[0]->term_id;
    $args=array(
    ‘tag__in’ => array($first_tag),
    ‘post__not_in’ => array($post->ID),
    ‘showposts’=>5,
    ‘caller_get_posts’=>1
    );
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
    while ($my_query->have_posts()) : $my_query->the_post(); ?>

    ” rel=”bookmark” title=”Permanent Link to < ?php the_title_attribute(); ?>“>< ?php the_title(); ?>

    < ?php
    endwhile;
    }
    }
    ?>

    Code:
    < ?php // Load Comments template (on single post pages, and "Page" pages, if set on options page)
    if ( is_single() OR ( is_page() && $bfa_ata_comments_on_pages == "Yes") ) {
    if (function_exists('paged_comments')) {
    paged_comments_template(); // If plugin "Paged Comments" is activated, for WP 2.6 and older
    } else {
    comments_template(); // This will load either legacy comments template (for WP 2.6 and older) or the new standard comments template (for WP 2.7 and newer)
    }
    } ?>

    If possible, I’d like to delete the PHP Related Posts hack and replace it with a reputable plugin. Then I’d like to get the comments sorted out.
    Thanks.

    # July 10, 2009 at 9:33 am

    I managed to fix it by messing with the PHP – removing the part I thought was responsible for the related posts. Guess I’ll try one of the plugins and see how those work.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".