飞龙博客

feilong.org 前端开发教程

wordpress侧边栏文章和访客数量统计代码

飞龙更新于 2011-12-04 08:08 加入书签 CTRL+D 有 96 个朋友来过

放出飞龙自己写的wordpress侧边栏文章和访客数量统计代码,供朋友们参考使用。本日志修订网址:http://feilong.org/count-posts-wordpress-sidebar 第一种没有用到插件,第二中使用了WP-Statistics插件,大家可以选择其中的一种方法即可。

 
//need no plugin
function fl_counts(){
// Posts
$num_posts = wp_count_posts( 'post' );
$num = number_format_i18n( $num_posts->publish );
$feilong = _n( 'Post', 'Posts', intval($num_posts->publish) );
echo '<li class="postsnum">' . $num . $feilong . '</li>';
 
// Pages
$num_pages = wp_count_posts( 'page' );
$num = number_format_i18n( $num_pages->publish );
$feilong = _n( 'Page', 'Pages', $num_pages->publish );
echo '<li class="pagesnum">' . $num . $feilong . '</li>';
 
// Categories
$num_cats  = wp_count_terms('category');
$num = number_format_i18n( $num_cats );
$feilong = _n( 'Category', 'Categories', $num_cats );
echo '<li class="catsnum">' . $num . $feilong . '</li>';
 
// Tags
$num_tags = wp_count_terms('post_tag');
$num = number_format_i18n( $num_tags );
$feilong = _n( 'Tag', 'Tags', $num_tags );
echo '<li class="tagsnum">' . $num . $feilong . '</li>';
 
// Approved Comments
$num_comm = wp_count_comments( );
$num = number_format_i18n($num_comm->approved);
$feilong =_n( 'Comment', 'Comments', $num_tags );
echo '<li class="commsnum">' . $num . $feilong . '</li>';
 
//users
$users_of_blog = count_users();
$total_users = $users_of_blog['total_users'];
$num = number_format_i18n($total_users);
$feilong = _n( 'Tag', 'Tags', $total_users );
echo '<li class="usersnum">' . $num . $feilong . '</li>';
}//20111205
 
function fl_side_counts(){
//needs WP-Statistics plugin
echo '<ul>';
echo '<li>访问次数: '; wp_statistics_total();echo '</li>';
//echo '<li>今日访问: '; wp_statistics_today();echo '</li>';
echo '<li>日志数量: '; wp_statistics_countposts();echo '</li>';
echo '<li>评论数量: '; wp_statistics_countcomment();echo '</li>';
echo '<li>最近更新: '; wp_statistics_lastpostdate();echo '</li>';
echo '<li>注册用户: '; wp_statistics_countusers();echo '</li>';
echo '<li>在线人数: '; wp_statistics_useronline();echo '</li>';
echo '</ul>';
}//20111108 feilong.org

有什么问题可以联系我。

飞龙初发:
2011-12-04 08:08
本文更新网址:
https://feilong.org/count-posts-wordpress-sidebar

所在目录: wordpress

新作:

旧文:

  • html css js
  • angular react vue
  • flutter python