当前位置:首页WP教程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();?>

给TA打赏
共{{data.count}}人
人已打赏
WP教程

WordPress如何移除菜单导航中自带的多余Class类名

2023-3-8 22:16:43

WP教程

WordPress如何调用全站随机文章/同分类随机文章

2023-3-8 22:16:47

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
购物车
优惠劵
有新私信 私信列表
搜索