Advertisement
Twansparant

Better related posts warning

Nov 15th, 2011
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.20 KB | None | 0 0
  1. <?php
  2.     $scores = the_related_get_scores(get_the_ID(), array(
  3.         'usept' => array(
  4.             'post'  => true
  5.         ),
  6.         'usetax'        => array(
  7.             'post_tag'  => true
  8.         ),
  9.     ));
  10.     $posts = array_slice(array_keys( $scores ), 0, 5 ); // keep only the the five best results
  11.     $args = array(
  12.         'suppress_filters' => true, // necessary in combination with the sticky-custom-post-types plugin
  13.         'post__in'          => $posts,
  14.         'posts_per_page'    => 5,
  15.         'caller_get_posts'  => 1,
  16.     );
  17.     $my_query = new WP_Query( $args );
  18.     function orderby( $a, $b ) {
  19.         global $posts;
  20.         $apos   = array_search( $a->ID, $posts );
  21.         $bpos   = array_search( $b->ID, $posts );
  22.         return ( $apos < $bpos ) ? -1 : 1;
  23.     }
  24.     usort( $my_query->posts, "orderby" );
  25.     if ( $my_query->have_posts()) { ?>
  26.         <ul class="posts">
  27.         <?php while ( $my_query->have_posts()) : $my_query->the_post(); ?>
  28.            <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?> - <span class="list-date"><?php echo get_the_date(); ?></span></a></li>
  29.         <?php endwhile; ?>
  30.         <?php wp_reset_query(); ?>
  31.         </ul>
  32.     <?php } else { ?>
  33.         <p>No related features found</p>
  34.     <?php } ?>
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement