开发者

Can't echo wp_count_posts('page')?

I'm trying to echo the value of the variable in the code below. I'm getting an error 开发者_开发百科(see below)...

Here's the code...

$mypagecount = wp_count_posts('page');
echo $mypagecount;

Here's the error:

Catchable fatal error: Object of class stdClass could not be converted to string


The wp_count_posts function returns an object.
You can ask the object to return the number of publish items.

<?php
     $count_pages = wp_count_posts('page');
     $pages = $count_pages->publish;
     echo $pages;
?>

For more information:
http://wpengineer.com/show-amount-of-posts-pages-categories-tags-comments-for-wordpress-themes/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜