Make related posts random
-
So I’m trying to make related posts on my website more random, atm. it shows almost same posts on every other post. I’m pretty sure it’s about orderby arg but i’m not sure how to implement that.
Code i’m using for it:
if(!function_exists('cherry_related_posts')){ function cherry_related_posts($args = array()){ global $post; $default = array( 'post_type' => get_post_type($post), 'class' => 'related-posts', 'class_list' => 'related-posts_list', 'class_list_item' => 'related-posts_item', 'display_title' => true, 'display_link' => true, 'display_thumbnail' => true, 'width_thumbnail' => 250, 'height_thumbnail' => 150, 'before_title' => '<h3 class="related-posts_h">', 'after_title' => '</h3>', 'posts_count' => 14 ); extract(array_merge($default, $args)); $post_tags = wp_get_post_terms($post->ID, $post_type.'_tag', array("fields" => "slugs")); $tags_type = $post_type=='post' ? 'tag' : $post_type.'_tag' ; $suppress_filters = get_option('suppress_filters');// WPML filter $blog_related = apply_filters( 'cherry_text_translate', of_get_option('blog_related'), 'blog_related' ); if ($post_tags && !is_wp_error($post_tags)) { $args = array( "$tags_type" => implode(',', $post_tags), 'post_status' => 'publish', 'posts_per_page' => $posts_count, 'ignore_sticky_posts' => 1, 'post__not_in' => array($post->ID), 'post_type' => $post_type, 'suppress_filters' => $suppress_filters ); query_posts($args); if ( have_posts() ) { $output = '<div class="'.$class.'">'; $output .= $display_title ? $before_title.$blog_related.$after_title : '' ; $output .= '<ul class="'.$class_list.' clearfix">'; while( have_posts() ) { the_post(); $thumb = has_post_thumbnail() ? get_post_thumbnail_id() : PARENT_URL.'/images/empty_thumb.gif'; $blank_img = stripos($thumb, 'empty_thumb.gif'); $img_url = $blank_img ? $thumb : wp_get_attachment_url( $thumb,'full'); $image = $blank_img ? $thumb : aq_resize($img_url, $width_thumbnail, $height_thumbnail, true) or $img_url; $output .= '<li class="'.$class_list_item.'">'; $output .= $display_thumbnail ? '<figure class="thumbnail featured-thumbnail"><a href="'.get_permalink().'" title="'.get_the_title().'"><img data-src="'.$image.'" alt="'.get_the_title().'" /></a></figure>': '' ; $output .= $display_link ? '<a href="'.get_permalink().'" >'.get_the_title().'</a>': '' ; $output .= '</li>'; } $output .= '</ul></div>'; echo $output; } wp_reset_query(); } } }
i have tried changing line:
$post_tags = wp_get_post_terms($post->ID, $post_type.'_tag', array("fields" => "slugs"));
to
$post_tags = wp_get_post_terms($post->ID, $post_type.'_tag', array("fields" => "slugs", "orderby" => "rand"));
but nothing changed.Any help with that?
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Make related posts random’ is closed to new replies.