Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

WordPress Better Related Links

By: a guest on Aug 31st, 2011  |  syntax: None  |  size: 0.78 KB  |  views: 128  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php /*
  2.         TEMPLATE PART TO DISPLAY RELATED TIPS
  3. */
  4.     $scores = the_related_get_scores(); // pass the post ID if outside of the loop
  5.     $posts = array_slice( array_keys( $scores ), 0, 5 ); // keep only the the five best results
  6.     $args = array(
  7.         'post__in'          => $posts,
  8.                 'post_type'         => 'my_type',
  9.         'posts_per_page'    => 5,
  10.         'caller_get_posts'  => 1 // ignore sticky status
  11.     );
  12.     $query = new WP_Query( $args );
  13.  
  14.     if ( $query->have_posts() ) { ?>
  15.                
  16.                 <h4>Related Posts</h4>
  17.                 <ul>
  18.                 <?php while ( $query->have_posts() ) {
  19.                                 $query->the_post();
  20.                         ?>
  21.                                 <li><a href="<?php echo get_permalink(get_the_ID()); ?>"><?php the_title(); ?></a></li>
  22.                 <?php } /* end while */ ?>
  23.                 </ul>
  24.         <?php } /* end if */ ?>