php - 在每次页面刷新时获取不同的随机帖子
问题描述
我需要帮助在每次页面刷新时显示不同的随机帖子。
我正在使用函数 orderby=rand,但这会在我拥有的每篇博文上给出相同的随机帖子。我需要在每次页面刷新时都有不同的帖子,不知道我该如何实现。
我目前有这个代码:
<div class="container">
<div class="ltblg text-center">Related Posts</div>
<div class="row">
<?php
$args = array( 'posts_per_page' => '3','order'=>'ASC','orderby'=>'rand' );
$recent_posts = new WP_Query($args);
while( $recent_posts->have_posts() ) :
$recent_posts->the_post()
?>
<div class="col-md-4 ">
<div class="blgbox">
<div class="latebog">
<?php
if (has_post_thumbnail()) {
the_post_thumbnail();
} else {
echo "<img src='/wp-content/uploads/2018/04/bydeaulfblog.png'/>";
}
?>
</div>
<div class="blogheading blglist relttle">
<a href="<?php echo get_permalink(); ?>">
<?php echo wp_trim_words( get_the_title(), 15 ); ?>
</a>
</div>
<div class="blgdate text-uppercase">
<?php the_time('F jS, Y') ?>
</div>
<div class="blgtet">
<p>
<?php echo wp_trim_words( get_the_content(), 25, '...' );?>
</p>
</div>
<a href="<?php echo get_permalink(); ?>" class="blgrdbtn">Read More
<span><img src="/wp-content/uploads/2018/03/rightarrw.png" /></span>
</a>
</div>
</div>
<?php endwhile; ?>
<?php wp_reset_postdata();
# reset post data so that other queries/loops work
?>
</div>
</div>
提前致谢!
解决方案
推荐阅读
- firebase - 如何使用流生成器检查 Firebase 文档的长度
- javascript - 通过浏览器控制台最后选择的元素的 XPath?
- swift - 如何在 Vapor 4 (Fluent 4) 中使用 User-Search-Terms 防止 SQL 注入
- azure-devops - DevOps 是否支持提交模板?
- r - 使用聚合和 dplyr,我为每个组返回相同的平均值
- javascript - React/javascript 组件将数据发送回 aspx
- google-app-engine - 如何从 Google App Engine 调用 Google Cloud Function?
- reactjs - 在reactjs中基于条件渲染隐藏下拉菜单
- mysql - 找不到库:libmysqlclient.so.18
- java - java.lang.NoClassDefFoundError: javax/xml/ws/WebServiceRef