首页 WordPress教程 WordPress如何调用最新/热门/指定分类文章
正文 评论

WordPress如何调用最新/热门/指定分类文章

获取数据是我们在开发一款WordPress主题时经常会用到的,随着主题功能越来越多、需求的多样性,调用文章的需求也变得多种多样,最常见是应该是调用最新文章、调用热门文章、调用指定分类文章了。

今天主题君带来一篇关于调用最新/热门/指定分类文章的WordPress教程,希望能对大家有所帮助。

指定分类文章

<?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 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$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();?>
-=||=-收藏赞 (0)
更多主题
v1.0.0
小程序收录免费WordPress主题:XCX主题
¥ 0 关注:21,683
详情
单栏极简文艺WordPress博客主题:Diaspora主题
¥ 0 关注:21,681
详情
简约黑白WordPress个人博客主题:Personal主题
¥ 0 关注:21,316
详情
v1.0.0
一款简约单栏的免费WordPress博客主题:itheme主题
¥ 0 关注:19,265
详情
功能丰富切轻量的WordPress虚拟资源主题:Rizhuti主题
¥ 599 关注:19,240
详情
v3.4.0
适用自媒体资讯的免费WordPress主题:Autumn主题
¥ 0 关注:16,484
详情
回复
暂无评论

不要再留垃圾评论了,主题君整理资源不容易,留几句鼓励的话吧。