Adding a Site Widget to a WordPress Theme to Display Website Overview Data

3,840 0

I've been blogging for nearly two months, and recently I wanted to see how many page views I've gained during these two months. This reminded me of a website overview widget. This widget is not integrated into the theme by default and needs to be added manually. If you know PHP, you can integrate it directly into the theme.

Below is a screenshot of how it looks on this site for your reference. You can also modify or replace the CSS styles as needed.

Code

PHP
<ul class="site-profile">
<li><i class="fa fa-file-o"></i> 文章总数:<?php $count_posts = wp_count_posts(); echo $published_posts = $count_posts->publish; ?></li>
<li><i class="fa fa-commenting-o"></i> 留言数量:<?php global $wpdb; echo $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments"); ?></li>
<li><i class="fa fa-folder-o"></i> 分类数量:<?php echo $count_categories = wp_count_terms('category'); ?></li>
<li><i class="fa fa-tags"></i> 标签总数:<?php echo $count_tags = wp_count_terms('post_tag'); ?></li>
<li><i class="fa fa-link"></i> 链接数量:<?php global $wpdb; echo $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->links WHERE link_visible = 'Y'"); ?></li>
<li><i class="fa fa-clock-o"></i> 运行时间:<?php echo floor((time() - strtotime("2007-8-1")) / 86400); ?></li>
<li><i class="fa fa-eye"></i> 浏览总量:<?php echo all_view(); ?></li>
<li><i class="fa fa-pencil-square-o"></i> 最后更新:<?php global $wpdb; $last = $wpdb->get_results("SELECT MAX(post_modified) AS MAX_m FROM $wpdb->posts WHERE (post_type = 'post' OR post_type = 'page') AND (post_status = 'publish' OR post_status = 'private')"); $last = date('Y年n月j日', strtotime($last[0]->MAX_m)); echo $last; ?></li>
</ul>

Notes

  1. Font Awesome icon library
    The code uses icons from the Font Awesome icon library. If the theme has already been configured with Font Awesome, the icons can be displayed directly. If the theme has not been configured, you can install the Font Awesome 4 Menus plugin to resolve this.
  2. Text box support for PHP
    When adding the widget, make sure the text box supports parsing PHP code so that the code above can work properly.

Comments

(0)

No comments yet. Start the conversation.

Leave a comment