知更鸟主题侧边栏网站概况美化修改

七月 14, 201916:12:25 评论 206
摘要

将知更鸟主题小工具“网站概况”进行表格化调整,从而达到美观的效果。感兴趣的可以在此基础上再添加一些色彩样式进行更进一步的美化。

知更鸟主题侧边栏网站概况美化修改

前言

这几天都在折腾网站,所以也就顺手记录一下一点东西了。知更鸟主题的侧边栏网站概况没有格式化,在其它博客看到有美化方式也就顺手修改了。其实也不是啥美化,不过是表格化了而已,不过也比原来的美观多了。下面就来说说修改方法。

第一种方法:修改主题文件

嗯,冰凝就采用了这种方法,不要问为什么,我就是想这么干。方法如下:

找到主题根目录下/inc/widgets.php文件,打开搜索“网站概况”找到下面这串代码

	<ul>
		<li><i class="be be-paper"></i>文章总数<span><?php $count_posts = wp_count_posts(); echo $published_posts = $count_posts->publish;?> 篇</span></li>
		<li><i class="be be-speechbubble"></i>评论留言<span><?php global $wpdb; echo $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments");?> 条</span></li>
		<li><i class="be be-folder"></i>分类目录<span><?php echo $count_categories = wp_count_terms('category'); ?> 个</span></li>
		<li><i class="be be-localoffer"></i>文章标签<span><?php echo $count_tags = wp_count_terms('post_tag'); ?> 个</span></li>
		<li><i class="be be-link"></i>友情链接<span><?php global $wpdb; echo $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->links WHERE link_visible = 'Y'"); ?> 个</span></li>
		<li><i class="be be-schedule"></i>网站运行<span><?php echo floor((time()-strtotime($instance['time']))/86400); ?> 天</span></li>
		<li><i class="be be-eye"></i>浏览总量<span><?php echo all_view(); ?> 次</span></li>
		<li><i class="be be-editor"></i>最后更新<span><?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; ?></span></li>
	</ul>

将上面的代码替换成下面的代码

    <table width="100%">
        <tbody>
            <tr>
                <td style="text-align:center;" width="50%"><i class="be be-paper"></i> 文章总数:</td>
                <td style="text-align:center;" width="50%">
                    <?php $count_posts = wp_count_posts(); echo $published_posts = $count_posts->publish;?> 篇</td>
            </tr>
            <tr>
                <td style="text-align:center;" width="50%"><i class="be be-speechbubble"></i> 留言数量:</td>
                <td style="text-align:center;" width="50%">
                   <?php global $wpdb; echo $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments");?> 条</td>
            </tr>
            <tr>
                <td style="text-align:center;" width="50%"><i class="be be-folder"></i> 分类目录:</td>
                <td style="text-align:center;" width="50%">
                    <?php echo $count_categories = wp_count_terms('category'); ?>个</td>
            </tr>
            <tr>
                <td style="text-align:center;" width="50%"><i class="be be-localoffer"></i> 标签总数:</td>
                <td style="text-align:center;" width="50%">
                    <?php echo $count_tags = wp_count_terms('post_tag'); ?>个</td>
            </tr>
            <tr>
                <td style="text-align:center;" width="50%"><i class="be be-link"></i> 友链链接:</td>
                <td style="text-align:center;" width="50%">
                    <?php global $wpdb; echo $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->links WHERE link_visible = 'Y'"); ?> 个</td>
                <tr>
                    <td style="text-align:center;" width="50%"><i class="be be-schedule"></i>安全运行:</td>
                    <td style="text-align:center;" width="50%">
                        <?php echo floor((time()-strtotime($instance['time']))/86400); ?>天</td>
                </tr>
                <tr>
                    <td style="text-align:center;" width="50%"><i class="be be-eye"></i> 浏览总量:</td>
                    <td style="text-align:center;" width="50%">
                        <?php echo all_view(); ?>次</td>
                </tr>
                <tr>
                    <td style="text-align:center;" width="50%"><i class="be be-editor"></i> 最后更新:</td>
                    <td style="text-align:center;" width="50%">
                        <?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; ?></td>
                </tr>
            </tr>
        </tbody>
    </table>

其实就是把它分栏表格化。到这里就结束了。

第二种方法:通过增强文本添加代码

这个方法最简单了,也是其它博客分享的方法,就是后台添加小工具→增强文本,然后把下面的代码直接复制下来改一下图标代码和建站时间就ok了。具体代码如下:

<div class="table-r">
    <table width="100%">
        <tbody>
            <tr>
                <td style="text-align:center;" width="50%"><i class="iconfont icon-activity"></i> 文章总数:</td>
                <td style="text-align:center;" width="50%">
                    <?php $count_posts=w p_count_posts(); echo $published_posts=$ count_posts->publish;?> 篇</td>
            </tr>
            <tr>
                <td style="text-align:center;" width="50%"><i class="iconfont icon-liuyan"></i> 留言数量:</td>
                <td style="text-align:center;" width="50%">
                    <?php global $wpdb; echo $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments");?> 条</td>
            </tr>
            <tr>
                <td style="text-align:center;" width="50%"><i class="iconfont icon-bianji"></i> 标签总数:</td>
                <td style="text-align:center;" width="50%">
                    <?php echo $count_tags=w p_count_terms( 'post_tag'); ?>个</td>
            </tr>
            <tr>
                <td style="text-align:center;" width="50%"><i class="iconfont icon-friendLink"></i> 友链链接:</td>
                <td style="text-align:center;" width="50%">
                    <?php global $wpdb; echo $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->links WHERE link_visible = 'Y'"); ?> 个</td>
                <tr>
                    <td style="text-align:center;" width="50%"><i class="iconfont icon-shouye"></i>安全运行:</td>
                    <td style="text-align:center;" width="50%">
                        <?php echo floor((time()-strtotime( "2016-5-6"))/86400); ?>天</td>
                </tr>
                <tr>
                    <td style="text-align:center;" width="50%"><i class="iconfont icon-weiyuqiang-"></i> 浏览总量:</td>
                    <td style="text-align:center;" width="50%">
                        <?php echo all_view(); ?>次</td>
                </tr>
                <tr>
                    <td style="text-align:center;" width="50%"><i class="iconfont icon-xinwen"></i> 最后更新:</td>
                    <td style="text-align:center;" width="50%">
                        <?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; ?></td>
                </tr>
            </tr>
        </tbody>
    </table>
</div>

记录到此完毕,感兴趣的其实可以再添加点色彩样式。

avatar
冰凝梦想

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: