wordpress文章数量统计函数wp_count_posts()

wp_count_posts()是用于统计指定文章类型文章数量的wordpress函数,通过wp_count_posts()函数可以统计所有类型的文章数量,如post、page或自定义文章类型post_type等,还可以计算指定状态的文章,如已发布、定时发布、草稿、待审、私有等。

<?php wp_count_posts('type', 'readable'); ?>

type -(字符)可选,指定文章的类型(post_type),如post、page或其它自定义文章类型,默认为post。

perm -(字符)可选,该参数可将私密文章状态算入文章状态中,使用“readable”并要求用户登录,默认为空。

wp_count_posts()的返回值为数组

stdClass Object
(
    [publish] => 11	//已发布
    [future] => 0	//定时发布
    [draft] => 0	//草稿
    [pending] => 0	//待审
    [private] => 0	//私有
    [trash] => 0	//垃圾箱
    [auto-draft] => 34	//自动草稿
    [inherit] => 0	//修订版本
    [request-pending] => 0
    [request-confirmed] => 0
    [request-failed] => 0
    [request-completed] => 0
)

1、获取已发布文章的数量、

<?php 
	$count = wp_count_posts();
	$getCount = $count->publish;
	echo $getCount;
?>

2、获取已发布页面的数量

<?php 
	$count = wp_count_posts('page');
	$getCount = $count->publish;
	echo $getCount;
?>
© 版权声明
THE END
喜欢就支持一下吧
点赞10
分享
评论 抢沙发

请登录后发表评论