wordpress外观模板修改的Tips汇总

众所周知,wordpress主要由国外人编写,包括大部分插件,因此wordpress对中文支持并不好,所以即使wordpress主题也可能需要部分修改翻译过来,另外还有关于一些插件扩展的Tips,均在此一一记录,以供查阅。

1,如何在wordpress博客侧栏添加微博或广告等Widget

在“主题”——“编辑”——“sidebar.php”如下位置添加红色微博代码,其他代码类似添加(红色为插入示例代码):

<!-- #primary .widget-area -->
<iframe frameborder="0" scrolling="no" src="https://show.v.t.qq.com/index.php?c=show&a=index&n=galois21&w=202&h=802&fl=1&l=2&o=13&co=4&cs=656565_A7A7A7_002343_838383" width="202" height="802">
</iframe>
 <?php
	// A second sidebar for widgets, just because.

其中个人腾讯微博代码获取参照:http://dev.t.qq.com/websites/share/

2,修改wordpress默认字体

字体:wordpress默认都是英文字体,对于中文博客颇有不适,在“主题”——“编辑”——“style.css”中,统一将“font-family”字段改为 ‘微软雅黑’, ‘黑体’, ‘宋体’,这样看起来就舒服很多了。

文章字体大小:字体默认16px,过大,国内网页设计标准是14px或者12px,同样在该style.css中找到该部分代码,将16px字体改为14px,行距24px改为20px

#content textarea {
  color: #333;
  font-size: 14px;   /* 16 to 14---------------------------------------- */
  line-height: 20px;  /* 24 to 20------------------------------------- */
 }

3、不依靠插件实现统计访客量

在functions.php尾部添加统计和显示函数

/*访问量*/
function getPostViews($postID){
    $count_key ='post_views_count';
    $count = get_post_meta($postID, $count_key, true);
    if($count==''){
        delete_post_meta($postID, $count_key);
        add_post_meta($postID, $count_key, '0');
        return "浏览(<b>0</b>) | ";
    }
  return "浏览(<b>". $count.'</b>) | ';
}
function setPostViews($postID) {
    $count_key = 'post_views_count';
    $count = get_post_meta($postID, $count_key, true);
    if($count==''){
        $count = 0;
        delete_post_meta($postID, $count_key);
        add_post_meta($postID, $count_key, '0');
    }
    elseif(is_user_logged_in()){}
    else{
        $count++;
        update_post_meta($postID, $count_key, $count);
    }
}

统计引用:<?php    setPostViews(get_the_ID());    ?>    插入到文章页面 single.php主循环内

显示引用:<?php    echo getPostViews(get_the_ID());    ?>  插入到想要显示的位置中,如functions.php的twentyten_posted_in()函数(文章页面)中、loop.php这个文章列表页面中

4、添加google-code-prettify代码插件

将foot或者其他页面中引入如下代码:

<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js?lang=css&skin=sunburst"></script>

链接中lang和skin参数可自行配置:http://code.google.com/p/google-code-prettify/wiki/GettingStarted

lang参数一般默认css即可

skin可选参数页:http://google-code-prettify.googlecode.com/svn/trunk/styles/index.html

浏览量(955) | 此条目发表在计算机分类目录,贴了, , 标签。将固定链接加入收藏夹。

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据