Related Posts

Forums Forums SwiftThemes Support Related Posts


This topic contains 4 replies, has 3 voices, and was last updated by  Sunita Kumari 2 years, 9 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
  • #30972

    <div class=”site-info”>Site url:<br>Version:Version 7 beta 3</div>Hello Mr. Satish,
    I will trouble once more. I have the server for my site is WPEngine. and it does not allow YAARP for related post. However, they allow some plugins like contextly, outbrain, but these are not suitable for me. Hence, I decided to add related post by adding some codes to post.single.php. But when I add these codes, my comments in my posts become attached to the related post. Then what should be the codes. If you suggest I would be grateful.

    My codes are

    //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 'You might also like';
      $first_tag = $tags[0]->term_id;
        'tag__in' => array($first_tag),
        'post__not_in' => array($post->ID),
      $my_query = new WP_Query($args);
      if( $my_query->have_posts() ) {
        while ($my_query->have_posts()) : $my_query->the_post(); ?>
          <li><a>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>

    Satish Gandham

    Add wp_reset_query(); after endwhile;


    I have been looking for this for some time where exactly do I place this above code in single php?


    yeah, Thank you so much mr. satish.


    Hello Mr. Satish, I am trying to add related posts without plugin as WPengine doesn’t allow. I am including following piece of codes

    <?php $orig_post = $post;
    global $post;
    $tags = wp_get_post_tags($post->ID);
    if ($tags) {
    $tag_ids = array();
    foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id;
    'tag__in' => $tag_ids,
    'post__not_in' => array($post->ID),
    'posts_per_page'=>2, // Number of related posts that will be shown.
    $my_query = new wp_query( $args );
    if( $my_query->have_posts() ) {
    echo '<div id="relatedposts"><h3>Related Posts</h3><ul>';
    while( $my_query->have_posts() ) {
    $my_query->the_post(); ?>
    <li><div class="relatedthumb"><a href="<? the_permalink()?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_post_thumbnail(array(150,100)); ?></a></div>
    <div class="relatedcontent">
    <h3><a href="<? the_permalink()?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></h3>
    <?php the_time('M j, Y') ?>
    <? }
    echo '</ul></div>';
    $post = $orig_post;
    wp_reset_query(); ?>

    But the related posts appear vertically aligned and awkward. How to keep them horizontal. thanks in advance.

    • This reply was modified 2 years, 9 months ago by  Sunita Kumari.
Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.