我购买了一个具有相关帖子功能的主题,但它按最新版本进行排序,因此同一类别中的所有我的帖子都具有相同的相关帖子内容。我想将此设置为随机,但不知道如何设置。尝试在这里查看一些帖子,但它被wordpress网站崩溃了。
感谢advanced中的帮助!
<?php
$orig_post = $post;
global $post;
$categories = get_the_category($post->ID);
if ($categories) {
$category_ids = array();
foreach($categories as $individual_category) $category_ids[] = $individual_category->term_id;
if(vp_metabox(\'manna_post.post_size\') == \'full_post\' && is_single()) :
$args = array(
\'category__in\' => $category_ids,
\'post__not_in\' => array($post->ID),
\'posts_per_page\' => 5, // Number of related posts that will be shown.
\'ignore_sticky_posts\' => 1
);
else :
$args = array(
\'category__in\' => $category_ids,
\'post__not_in\' => array($post->ID),
\'posts_per_page\' => 4, // Number of related posts that will be shown.
\'ignore_sticky_posts\' => 1
);
endif;
$my_query = new wp_query( $args );
if( $my_query->have_posts() ) { ?>
<div class="post-related"><h4 class="block-heading"><span><?php _e(\'You Might Also Like\', \'cassia\'); ?></span></h4><ul>
<?php if(vp_metabox(\'manna_post.post_size\') == \'full_post\' && is_single()) : ?>
<?php while( $my_query->have_posts() ) :
$my_query->the_post();?>
<li>
<div class="related-item full">
<?php $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); ?>
<a href="<?php echo get_permalink() ?>" rel="bookmark"><img src="<?php echo aq_resize($url,176,130,true,true,true); ?>" /></a>
<h4><a href="<?php echo get_permalink() ?>" rel="bookmark" title="Permanent Link: <?php the_title(); ?>"><?php the_title(); ?></a></h4>
</div>
</li>
<?php
endwhile;
else : ?>
<?php while( $my_query->have_posts() ) :
$my_query->the_post(); ?>
<li>
<div class="related-item">
<?php if ( (function_exists(\'has_post_thumbnail\')) && (has_post_thumbnail()) ) { ?>
<a href="<?php echo get_permalink() ?>" rel="bookmark"><?php the_post_thumbnail(\'related\'); ?></a>
<?php } ?>
<h4><a href="<?php echo get_permalink() ?>" rel="bookmark" title="Permanent Link: <?php the_title(); ?>"><?php the_title(); ?><br><br><?php the_time( get_option(\'date_format\') ); ?></a></h4>
</div>
</li>
<?php
endwhile;
endif;
echo \'</ul></div>\';
} else {
if(is_home() || is_archive()) {
echo \'<div class="related-divider"></div>\';
}
}
}
$post = $orig_post;
wp_reset_query();
?>