最新公告
  • 欢迎您光临牛品源码,本站秉承服务宗旨 履行“站长”责任,销售只是起点 服务永无止境!立即加入我们
  • WordPress如何调用最新、热门文章和指定分类文章

    在我们WordPress主题制作过程过用到最多的应该是调用文章的代码了,而根据主题功能需求的多样性,调用文章的需求也变得花里胡哨。

    下面牛品源码分享了几段WordPress调用最新、热门文章的代码实例

    最新文章

    <?php query_posts(\'showposts=6&cat=1\'); ?> // 显示文章篇数和显示分类
    <?php while (have_posts()) : the_post(); ?>
    
    <a href=\"<?php the_permalink() ?>\" rel=\"external nofollow\" ><?php the_title(); ?></a>
    
    <?php endwhile;?> 
    

    指定分类文章

    <?php query_posts(\'cat=1&showposts=5\'); //cat是要调用的分类ID,showposts是需要显示的文章数量 ?>
    <?php while (have_posts()) : the_post(); ?>
    
    <a href=\"<?php the_permalink(); ?>\" rel=\"external nofollow\"  rel=\"external nofollow\"  ><?php the_title(); ?></a>
    
    <?php endwhile; wp_reset_query(); ?>
    

    调用整站热门文章(按评论数排序)

    <?php
    $post_num = 10; // 显示篇数
    $args = array(
    \'post_status\' => \'publish\', // 只选公开的文章.
    \'post__not_in\' => array($post->ID),//排除当前文章
    \'caller_get_posts\' => 1, // 排除置顶文章.
    \'orderby\' => \'comment_count\', // 依评论数排序.
    \'posts_per_page\' => $post_num
    );
    $query_posts = new WP_Query();
    $query_posts->query($args);
    while( $query_posts->have_posts() ) { $query_posts->the_post(); ?>
    
    <a href=\"<?php the_permalink(); ?>\" rel=\"external nofollow\"  rel=\"external nofollow\"   ><?php the_title(); ?></a>
    
    <?php } wp_reset_query();?>
    

     

    文章来自牛品源码www.zjw13.xyz转载请保留本链接,谢谢!

    发表评论

    售后服务:

    • 售后服务范围 1、商业模板使用范围内问题免费咨询
      2、源码安装、模板安装(一般 ¥50-500)服务答疑仅限SVIP用户
      3、单价超过200元的模板免费一次安装,需提供服务器信息。
      付费增值服务 1、提供dedecms模板、WordPress主题、discuz模板优化等服务请详询在线客服
      2、承接 WordPress、DedeCMS、Discuz 等系统建站、仿站、开发、定制等服务
      3、服务器环境配置(一般 ¥50-500)
      4、网站中毒处理(需额外付费,1000元/次/质保三个月)
      售后服务时间 周一至周日(法定节假日除外) 9:00-23:00
      免责声明 本站所提供的模板(主题/插件)等资源仅供学习交流,若使用商业用途,请购买正版授权,否则产生的一切后果将由下载用户自行承担,有部分资源为网上收集或仿制而来,若模板侵犯了您的合法权益,请来信通知我们(Email: niupinyuanma@foxmail.com),我们会及时删除,给您带来的不便,我们深表歉意!