wordpress调用指定ID分类下浏览最多的内容

要在WordPress中调用指定ID分类下浏览最多的内容,你可以通过以下方法实现:

复制代码
<?php
$post_num = 8; // 设置调用条数
$wdpidproduct = 2; // 假设这是你要查询的分类ID
$args = array(
    'post_password' => '',
    'post_status' => 'publish', // wodepress.com
    'cat' => $wdpidproduct, // 只选择分类ID为$wdpidproduct的文章。
    'caller_get_posts' => 1, 
    'meta_key' => 'views', // 假设'views'是存储浏览次数的元数据键。
    'orderby' => 'meta_value_num', // 按元数据值的数字排序。
    'order' => 'DESC', // 降序排列,浏览数最多的文章在前。
    'posts_per_page' => $post_num
);
$query_posts = new WP_Query();
$query_posts->query($args);
while( $query_posts->have_posts() ) { $query_posts->the_post(); ?>
<li><?php comments_number('0', '1', '%' );?> 次评论: <br><a href="<?php the_permalink() ?>" title="<?php the_title() ?>"><?php the_title() ?></a></li>
<?php } wp_reset_query(); ?>

以上方式需要浏览量统计插件或自定义浏览量统计后才会生效,可以使用WP_Query类来查询指定分类下的热门文章。

原文

http://www.dulizhan.bj.cn/jianzhan/197.html

相关推荐
Web极客码4 天前
加快WooCommerce性能
服务器·wordpress·网站
豆豆7 天前
WordPress至PageAdmin CMS跨平台迁移技术指南:应对环境约束的系统化过渡方案
cms·wordpress·建站系统·内容管理系统·网站管理系统·pageadmin
Web极客码12 天前
Akismet对WordPress防垃圾评论
服务器·搜索引擎·wordpress
尘中客14 天前
【2026最新】如何用 WordPress 零代码搭建八字排盘/紫微斗数网站(附免费开源插件)
php·api·wordpress·建站源码·网站引流
WordPress学习笔记15 天前
B2B独立站与B2C独立站的主题模板选择的对不对很重要
wordpress·gracetheme·wodetheme
WordPress学习笔记15 天前
一般创业公司官网用WordPress主题模板完全足够
wordpress
lilihuigz16 天前
WordPress 7.0 AI基础设施详解:能力API、AI客户端与MCP适配器如何重塑插件生态
人工智能·wordpress·独立站
CSharp精选营16 天前
2026个人博客建站指南:这4种方案总有一款适合你
.net·wordpress·个人博客·独立站·githubpages·建站教程
WordPress学习笔记16 天前
WodeShop构建下一代高性能电商的核心驱动力
wordpress
WordPress学习笔记18 天前
推荐几个SEO友好的wordpress主题
wordpress