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();?>
文章来自小白学习资源站https://btzy.cc转载请保留本链接,谢谢!
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。源码素材属于虚拟商品,具有可复制性,可传播性,一旦授予,不接受任何形式的退款、换货要求。请您在购买获取之前确认好 是您所需要的资源
1.本站提供的一切源码、教程和内容信息仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途!
2.本站信息来自网络收集整理,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑或手机中彻底删除上述内容!
3.本站提供的源码,模板,插件等其他资源都不包含技术服务,敬请谅解!
4.本站资源售价只是赞助,收取费用仅维持本站日常运营所需!
5.如无备注,本站不保证所提供下载的资源准确性安全性和完整性,源码仅供下载学习之用!
6.如用于商业或者非法用途,与本站无关。一切后果请自行负责!
7.如果遇到加密压缩包,默认解压密码为:btzy.cc或bori99.com如遇到无法解压请联系站长!