javascript - Wordpress related posts only show the last three posts in the category. Is there a way to randomize every related post? -


my wordpress related posts shows last 3 recent posts created in each category. hoping have show random posts in each category. older post can viewed. not last 3 created. here's code below.

<?php $categories = get_the_category($post->id); if ($categories) { $category_ids = array(); foreach($categories $individual_category) $category_ids[] = $individual_category->term_id;  $args=array( 'category__in' => $category_ids, 'post__not_in' => array($post->id), 'showposts'=>3, // number of related posts shown. 'caller_get_posts'=>1 ); $my_query = new wp_query($args); if( $my_query->have_posts() ) {     echo '<ul>';     while ($my_query->have_posts()) {         $my_query->the_post();     ?> <div class="relatedpost">       <a rel="external" href="<? the_permalink()?>"><?php the_post_thumbnail(array(175,98)); ?><br />   <center><h6><?php the_title(); ?></h6></center>      </a>   </div>   

add orderby rand in arguments , use below,

<?php     $posts = get_posts('orderby=rand&numberposts=5');     foreach($posts $post) { ?>    <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a> <?php } ?> 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -