Created
          January 26, 2014 05:47 
        
      - 
      
- 
        Save webhasan/8629000 to your computer and use it in GitHub Desktop. 
    wp: related post
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | <?php $orig_post = $post; | |
| global $post; | |
| $categories = get_the_category($post->ID); | |
| if($categories){ | |
| $categori_id = array(); | |
| foreach ($categories as $category) { | |
| $categori_id[] = $category->cat_ID; | |
| } | |
| $post_loop = new WP_Query(array( | |
| 'posts_per_page' => 3, | |
| 'category__in' => $categori_id, | |
| 'post__not_in' => array($post->ID), | |
| 'orderby' => 'rand' | |
| )); | |
| if($post_loop->have_posts()){ ?> | |
| <h2 class="related_post_title">Suggested Articles For You:</h2> | |
| <div class="related-post-area"> | |
| <ul> | |
| <?php while($post_loop->have_posts()){ ?> | |
| <?php $post_loop->the_post(); ?> | |
| <li> | |
| <a href="<?php the_permalink(); ?>" class="thumbnail-image" ><?php the_post_thumbnail(); ?></a> | |
| <h1 class="thumbnail-text"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1> | |
| </li> | |
| <?php } ?> | |
| </ul> | |
| </div> | |
| <?php } | |
| } | |
| $post = $orig_post; | |
| wp_reset_query(); | |
| ?> | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment