最新公告
  • 资源宝-专注于优秀资源,本站秉承服务宗旨 履行“站长”责任, 服务永无止境!
  • WordPress如何调用全站、同分类随机文章

    已弃用QQ,邮箱:[email protected] 【哔哩哔哩留言】上线看见信息第一时间回复,本站大部分源码亲测

    在我们的网站中会有很多地方用到随机显示文章,为了使我们的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(); ?>
    
    资源宝-—专注于优秀资源搜集共享与发布
    资源宝 » WordPress如何调用全站、同分类随机文章
    本站所有资源来源于网络,仅限用于学习研究;无任何技术支持!不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。信息来自网络,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑中彻底删除内容。如果您喜欢,请支持正版。如有侵权请邮件与我们联系处理。

     本站部分源码亲测,单个源码赞助前请咨询 

    网站底部横幅背景图
    • 99999访问总数
    • 206会员总数(位)
    • 9541资源总数(个)
    • 900 资源大小(GB)
    • 2379稳定运行(天)

    提供最优质的资源集合

    网站源码 APP源码