Advertisement
Guest User

WordPress Better Related Links

a guest
Aug 31st, 2011
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  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 */ ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement