文章目录
- //numberposts 为文章数量
5, ‘orderby’ => ‘rand’, ‘post_status’ => ‘publish’ );
$rand_posts = get_posts( $args );
foreach( $rand_posts as $post ) : ?><a href="” rel=”external nofollow” rel=”external nofollow” rel=”external nofollow” rel=”external nofollow” >
- $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="” rel=”external nofollow” rel=”external nofollow” rel=”external nofollow” rel=”external nofollow” >
文章来自小白学习资源站https://qyymz.com转载请注明出处,并保留本链接,谢谢!
在我们的网站中会有很多地方用到随机显示文章,为了使我们的wordpress主题功能更加的强大,wordpress随机文章是wordpress主题制作中必不可少的一项功能,
以下分享2段wordpress随机文章的代码片段。
//numberposts 为文章数量
5, 'orderby' => 'rand', 'post_status' => 'publish' );
$rand_posts = get_posts( $args );
foreach( $rand_posts as $post ) : ?>
<a href="" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
//numberposts 为文章数量
5, 'orderby' => 'rand', 'post_status' => 'publish' );
$rand_posts = get_posts( $args );
foreach( $rand_posts as $post ) : ?>
<a href="" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
$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="" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
$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="" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
文章来自小白学习资源站https://qyymz.com转载请注明出处,并保留本链接,谢谢!
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
