Forums

Related posts code displaying current post's info (1 post)

  1. rjpinney
    Member
    Posted 4 months ago #

    I am using a piece of code to pull similar posts into a particular area on each post page. The code is working in part - the links it pulls together are fine - but the text it displays for the links is taken from the page being viewed, rather than the destination. This is true for the title and thumbnail.

    I expect this is a fairly easy fix so please excuse my ignorance! Any help appreciated, code below.

    Thanks!

    <?php
      $tags = wp_get_post_tags($post->ID);
      $tagIDs = array();
      if ($tags) {
        $tagcount = count($tags);
        for ($i = 0; $i < $tagcount; $i++) {
          $tagIDs[$i] = $tags[$i]->term_id;
        }
        $args=array(
          'tag__in' => $tagIDs,
          '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(); ?>
    <?php echo get_the_post_thumbnail($page->ID, 'mini-thumbnail'); ?>
            <div id="similarbook"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?> - <?php echo get_post_meta($post->ID, 'bookauthor', true); ?></a></div>
          <?php endwhile;
        }
      }
    ?>

Reply

You must log in to post.

About this Topic