otw_related_posts

The Carbon Light - Business responsive otw related posts function.

Description

otw_related_posts( $postID ); 

Parameters (1)

0. $postid
The postID.

Usage

  1. if ( !function_exists( 'otw_related_posts' ) ) { 
  2. require_once '/functions.php'; 
  3.  
  4. // The postID. 
  5. $postid = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = otw_related_posts($postid); 
  9.  

Defined (1)

The function is defined in the following location(s).

/functions.php  
  1. function otw_related_posts($postID) { 
  2. $tags = wp_get_post_tags($postID); 
  3. if ($tags) { 
  4. $tag_ids = array(); 
  5. foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id; 
  6. $args=array( 
  7. 'tag__in' => $tag_ids,  
  8. 'post__not_in' => array($postID),  
  9. 'showposts'=>5, // Number of related posts that will be shown. 
  10. 'ignore_sticky_posts'=>1 
  11. ); 
  12. $my_query = newwp_query$args); 
  13. if( $my_query->have_posts() ) { 
  14. echo '<h3 class="widget-title">'.__('Related Posts', 'otw-carbon-light').'</h3><ul class="otw-list">'; 
  15. while ($my_query->have_posts()) { 
  16. $my_query->the_post(); 
  17. ?> 
  18. <li><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></li> 
  19. <?php 
  20. echo '</ul>'; 
  21. wp_reset_query();