Advertisement
Guest User

Untitled

a guest
Jun 30th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. global $wiles_option;
  2.  
  3. $categories = get_the_category( $post->ID );
  4. $first_cat ='';
  5. if(isset($categories[0]->cat_ID)){
  6. $first_cat = $categories[0]->cat_ID;
  7. }
  8. $posts_to_show = $wiles_option['single_related_posts_to_show'];
  9. $args = array(
  10. 'category__in' => array( $first_cat ),
  11. 'post__not_in' => array( $post->ID ),
  12. 'posts_per_page' => 3,
  13. 'orderby' => 'rand'
  14. );
  15.  
  16. $related_posts = get_posts( $args );
  17. if( $related_posts ) {
  18. ?>
  19.  
  20. <section class="single-box related-articles">
  21. <h4 class="entry-title">
  22. <?php _e('You May Also Like', 'wiles'); ?>
  23. </h4>
  24.  
  25. <?php foreach( $related_posts as $post ): setup_postdata( $post ); ?>
  26.  
  27. <div class="related-article four-col">
  28.  
  29. <figure class="entry-image">
  30.  
  31. <a href="<?php the_permalink(); ?>">
  32. <?php
  33. if ( has_post_thumbnail() ) {
  34. the_post_thumbnail( 'small');
  35. } else { ?>
  36. <img src="<?php echo get_template_directory_uri(); ?>/images/default-image.png" alt="<?php the_title(); ?>" />
  37. <?php } ?>
  38. </a>
  39.  
  40. </figure>
  41. <h5><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h5>
  42.  
  43.  
  44.  
  45. </div>
  46.  
  47. <?php endforeach; ?>
  48.  
  49.  
  50.  
  51.  
  52.  
  53. </section><!-- .single-box .related-posts -->
  54.  
  55. <?php
  56. } else {
  57. return;
  58. }
  59.  
  60. wp_reset_postdata();
  61.  
  62.  
  63. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement