0

这是我面临的问题。我正在使用 Wordpress,并且正在使用两个 PHP 在我的网站上向访客显示统计信息,例如# total of postscreated 和# of total commentson the site。PHP 运行良好并显示当前实时#,但它们不呈现逗号,例如2,700在 which show as2700和 say for another example 100,800which shows as 100800.

谁能告诉我如何修改这两个 php 来实现这一点?

这是帖子状态PHP代码:

<?php
$postcount = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'publish'");
echo $postcount;
?>

Here is the comments status php:

<?php
$comments_count = wp_count_comments();
echo "" . $comments_count->total_comments . "";
?>

提前致谢。

-杰伊

4

2 回答 2

1

您正在寻找: http: //php.net/manual/en/function.number-format.php

number_format($postcount);

应该足以显示数千个分隔符。

第二次使用:

echo "" . number_format($comments_count->total_comments) . "";
于 2013-04-09T20:36:18.580 回答
1
<?php
  $postcount = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'publish'");
  echo number_format($postcount, 0); 
?>

关于评论数:

<?php
  $comments_count = wp_count_comments();
  echo "" . number_format($comments_count->total_comments, 0) . "";
?>
于 2013-04-09T20:36:56.727 回答