Related Posts

Forums Forums SwiftThemes Support Related Posts

Tagged: 

This topic contains 4 replies, has 3 voices, and was last updated by  Sunita Kumari 1 year, 5 months ago.

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

    Sunita Kumari
    Participant

    <div class=”site-info”>Site url: http://www.howto-connect.com/<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

    
     <?php
    //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;
      $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(); ?>
          <li><a>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
          <?php
        endwhile;
      }
    }
    ?>
    #30974

    Satish Gandham
    Keymaster

    Add wp_reset_query(); after endwhile;

    #30975

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

    #30977

    Sunita Kumari
    Participant

    yeah, Thank you so much mr. satish.

    #34882

    Sunita Kumari
    Participant

    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;
    $args=array(
    'tag__in' => $tag_ids,
    'post__not_in' => array($post->ID),
    'posts_per_page'=>2, // Number of related posts that will be shown.
    'caller_get_posts'=>1
    );
    $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') ?>
    </div>
    </li>
    <? }
    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 1 year, 5 months ago by  Sunita Kumari.
Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.