admin管理员组文章数量:1320610
I'm trying to format my post my total post count in the header of my site. I have the number in there but would like it to format with the commas eg 1,500 not 1500. I know this is probably really basic but I'm still learning.. any help would be much appreciated. Cheers
functions.php
function wpb_total_posts() {
$total = wp_count_posts()->publish;
echo '' . $total;
}
Header.php
<?php wpb_total_posts(); ?>
I'm trying to format my post my total post count in the header of my site. I have the number in there but would like it to format with the commas eg 1,500 not 1500. I know this is probably really basic but I'm still learning.. any help would be much appreciated. Cheers
functions.php
function wpb_total_posts() {
$total = wp_count_posts()->publish;
echo '' . $total;
}
Header.php
<?php wpb_total_posts(); ?>
Share
Improve this question
edited Oct 4, 2020 at 15:24
fuxia♦
107k38 gold badges255 silver badges459 bronze badges
asked Oct 4, 2020 at 15:19
JasonJason
133 bronze badges
1 Answer
Reset to default 1You can use the PHP function number_format()
.
function wpb_total_posts() {
$total = wp_count_posts()->publish;
echo number_format(
$total, // your number
0, // number of decimal points
'.', // decimal point separator
',' // thousands separator
);
}
Or, because you are using the default values anyway, you can shorten the function to:
function wpb_total_posts() {
echo number_format( wp_count_posts()->publish );
}
本文标签: postsNumber format for wpcountposts()
版权声明:本文标题:posts - Number format for wp_count_posts() 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742082237a2419769.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论