Advertisement
Guest User

Untitled

a guest
Jan 12th, 2014
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.65 KB | None | 0 0
  1. <?php
  2.  
  3. $orig_post = $post;
  4. global $post;
  5.  
  6. $tags = wp_get_post_tags( $post->ID );
  7.  
  8. if ($tags) {
  9.  
  10.     $tags_ids = array();
  11.  
  12.     foreach($tags as $individual_tag) $tags_ids[] = $individual_tag->term_id;
  13.  
  14.     if(vp_metabox('hickory_post.post_size') == 'full_post') :
  15.     $args = array(
  16.         'tag__in'     => $tags_ids,
  17.         'post__not_in'     => array($post->ID),
  18.         'posts_per_page'   => 5, // Number of related posts that will be shown.
  19.         'caller_get_posts' => 1
  20.     );
  21.     else :
  22.     $args = array(
  23.         'tag__in'     => $tags_ids,
  24.         'post__not_in'     => array($post->ID),
  25.         'posts_per_page'   => 3, // Number of related posts that will be shown.
  26.         'caller_get_posts' => 1
  27.     );
  28.     endif;
  29.  
  30.     $my_query = new wp_query( $args );
  31.     if( $my_query->have_posts() ) { ?>
  32.         <div class="post-related"><h3><?php _e('You Might Also Like', 'hickory'); ?></h3><ul>
  33.         <?php while( $my_query->have_posts() ) {
  34.             $my_query->the_post();?>
  35.             <li>
  36.                 <div class="related-item">
  37.                
  38.                     <?php if (  (function_exists('has_post_thumbnail')) && (has_post_thumbnail())  ) { ?>
  39.                     <a href="<?php echo get_permalink() ?>" rel="bookmark"><?php the_post_thumbnail('related'); ?></a>
  40.                     <?php } ?>
  41.                    
  42.                     <span class="cat">
  43.                     <?php
  44.                     $category = get_the_category(get_the_ID());
  45.                     if($category[0]){
  46.                         echo '<a href="'.get_category_link($category[0]->term_id ).'">'.$category[0]->cat_name.'</a>';
  47.                     }
  48.                     ?>
  49.                     </span>
  50.                     <h4><a href="<?php echo get_permalink() ?>" rel="bookmark" title="Permanent Link: <?php the_title(); ?>"><?php the_title(); ?></a></h4>
  51.                
  52.                 </div>
  53.             </li>
  54.         <?php
  55.         }
  56.         echo '</ul></div>';
  57.     }
  58. }
  59. $post = $orig_post;
  60. wp_reset_query();
  61.  
  62. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement