已弃用QQ,邮箱:[email protected] 【哔哩哔哩留言】上线看见信息第一时间回复,本站大部分源码亲测
在我们WordPress主题制作过程过用到最多的应该是调用文章的代码了,而根据主题功能需求的多样性,调用文章的需求也变得花里胡哨。
下面资源宝分享了几段WordPress调用最新、热门文章的代码实例
最新文章
<?php query_posts('showposts=6&cat=1'); ?> // 显示文章篇数和显示分类
<?php while (have_posts()) : the_post(); ?>
<a href="<?php%20the_permalink()%20?>" 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%20the_permalink();%20?>" 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%20the_permalink();%20?>" rel="external nofollow" rel="external nofollow" ><?php the_title(); ?></a>
<?php } wp_reset_query();?>
本站所有资源来源于网络,仅限用于学习研究;无任何技术支持!不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。信息来自网络,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑中彻底删除内容。如果您喜欢,请支持正版。如有侵权请邮件与我们联系处理。