在我们的网站中会有很多地方用到随机显示文章,为了使我们的wordpress主题功能更加的强大,wordpress随机文章是wordpress主题制作中必不可少的一项功能,
以下分享2段wordpress随机文章的代码片段。
整站随机文章
//numberposts 为文章数量
<?php
$args = array( 'numberposts' => 5, 'orderby' => 'rand', 'post_status' => 'publish' );
$rand_posts = get_posts( $args );
foreach( $rand_posts as $post ) : ?>
<a href="<?php%20the_permalink();%20?>" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><?php the_title(); ?></a>
<?php endforeach; ?>
同分类随机文章
<?php
$cat = get_the_category();
foreach($cat as $key=>$category){
$catid = $category->term_id;}
$args = array('orderby' => 'rand','showposts' => 8,'cat' => $catid ); // 显示文章篇数
$query_posts = new WP_Query();
$query_posts->query($args);
while ($query_posts->have_posts()) : $query_posts->the_post();?>
<a href="<?php%20the_permalink();%20?>" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><?php the_title(); ?></a>
<?php endwhile;?>
<?php wp_reset_query(); ?>

声明:
根据2013年1月30日《计算机软件保护条例》2次修订第17条规定: 为了学习和研究软件内含的设计思想和原理,通过安装、显示、传输或者存 储软件等方式使用软件的,可以不经软件著作权人许可,不向其支付报酬! 鉴于此,也希望大家按此说明研究软件!
1、本站所有资源来源于用户上传和网络,因此不包含技术服务请大家谅解!
2、下载用户仅供学习交流,若使用商业用途,请购买正版授权,否则产生的一切后果将由下载用户自行承担
3、站内资源均来源于网络公开发表文件或网友投稿发布,如侵犯您的权益,请联系管理员删除。
4、本站不保证所提供下载的资源的准确性、安全性和完整性,资源仅供下载学习之用!如有链接无法下载、失效或广告,请联系客服处理!
5、所有资源均收集于互联网仅供学习、参考和研究,请理解这个概念,所以不能保证每个细节都符合你的需求,也可能存在未知的BUG与瑕疵,因本站资源均为可复制品,所以不支持任何理由的退款兑现,请熟知后再支付下载!。