• Hi,

    I’m trying to get this excellent piece of code written by MichaelH to run in the sidebar —

    <?php $tags = wp_get_post_tags($post->ID); if ($tags) { $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 ); $rel_posts = new WP_Query($args); if( $rel_posts->have_posts() ) { while ($rel_posts->have_posts()) : $rel_posts->the_post(); ?> <div class="rel_posts"> <div class="rel_thumb"><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_post_thumbnail(array(130,130)); ?></a></div> <div class="rel_link"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></div> </div> <?php endwhile; } } ?> <div class="clearer"></div>

    If I add a text widget with exec-php, it won’t work because it seems to need to be in the loop so as to pick up the post’s tags. If I put a stripped down version of —

    <div class="rel_thumb"><a>" title="<?php the_title(); ?>"><?php the_post_thumbnail(array(130,130)); ?></a></div> <div class="rel_link"><a>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></div> </div>

    — In the widget, then obviously I can get the current post’s permalink and thumbnail to display, but I could get it to do that anyway. How can I get the related post by tag functionality to work in the sidebar? How can I get the script to read the tag from the actual post? I really need this to work in the sidebar rather than after the post.

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘related post by tags in sidebar problem’ is closed to new replies.