清源绿里

WordPress Theme: Into-The-Ocean

Into-The-Ocean作为一个相当不错的WordPress主题,被许多Blog称赞。这两天帮朋友建WP站,将它针对中文特点以及个人喜好修改了一些地方。

031

1,修改了Recent Posts内容表现方式

该主题在index.php右侧罗列Recent Post时,使用了the_content_rss。但该函数以空格对作为对word划分的标识,并输出自定义的word数目。对于中文来说,整个段落基本上不可能出现空格,因此这样的划分方式显然不适合中文WordPress站点。[本条在前篇日志中有提到,但作为总结一起归并到这里。]

修改方式:将the_content_rss这个函数由限定word数目改为限定字符数目。
修改方法:找到WordPress根目录includes文件夹中的feed.php,增加如下代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
function the_chinesecontent_rss($more_link_text='(more...)', $stripteaser=0, $more_file='', $cut = 0, $encode_html = 0) {
 $content = get_the_content($more_link_text, $stripteaser, $more_file);
 $content = apply_filters('the_content_rss', $content);
 if ( $cut && !$encode_html )
   $encode_html = 2;
 if ( 1== $encode_html ) {
  $content = wp_specialchars($content);
  $cut = 0;
 } elseif ( 0 == $encode_html ) {
  $content = make_url_footnote($content);
 } elseif ( 2 == $encode_html ) {
  $content = strip_tags($content);
 }
 if ( $cut ) {
  $excerpt =substr($content,0,$cut);
  $excerpt = utf8_trim($excerpt);
  $content = $excerpt.'...';
 }
 $content = str_replace(']]>', ']]>', $content);
 echo $content;
}

并将Into-The-Ocean文件夹中index.php里面

1
/?php the_content_rss('',FALSE,'',100);?/</p>

修改为

1
/?php the_chinesecontent_rss('',FALSE,'',100);?/</p>

如果你没有使用中文WordPress工具箱,则还需加入以下函数;如果你安装了工具箱,则严禁加入之下函数:

1
2
3
4
5
6
7
8
9
10
11
function utf8_trim($str) {
  $len = strlen($str);

  for ($i=strlen($str)-1; $i>=0; $i-=1){
    $hex .= ' '.ord($str[$i]);
    $ch = ord($str[$i]);
      if (($ch & 128)==0) return(substr($str,0,$i));
      if (($ch & 192)==192) return(substr($str,0,$i));
 }
 return($str.$hex);
}

2,修改宽度

将原来浮动100%的宽度,修改为固定1004px(IE),1008px(FireFox)

3,修改footer.php

改变原来的排列和内容。增加了Recent Comment(需要中文WordPress工具箱插件)。

4,修改一些字体大小

英文字体的尺寸并不适用于中文字符,所以放大了一些重要地方的字体,并将一些斜体改回正常(为了美观)。

5,修改一些box属性

为了clean_archives_reloaded插件能够顺利使用,增加了对#latest ul的padding定义。

6,修改header.php

Into-The-Ocean的header.php中没有加入wp_head(),会导致一些插件无法调用。

请在

1
</head>

前加入

1
/?php wp_head(); ?/

不知道是不是因为WordPress版本的缘故,Into-The-Ocean在WordPress 2.2.1下不能进行评论,总是提示请输入评论内容。这是个bug。

请在Into-The-Ocean文件夹中comment.php找到如下句子:

1
2
3
4
  <p><textarea name="comment_box" id="comment_box" cols="100%" rows="10" tabindex="4"></textarea></p>
 
  <p><input name="submit" type="submit" id="submit" tabindex="5" value="Submit" />
  <input type="hidden" name="comment_post_ID" value="/?php echo $id; ?/" /></p>

替换为:

1
2
3
4
  <p><textarea name="comment" id="comment" cols="100%" rows="10" tabindex="4"></textarea></p>
 
  <p><input name="submit" type="submit" id="submit" tabindex="5" value="Submit Comment" />
  <input type="hidden" name="comment_post_ID" value="/?php echo $id; ?/" /></p>

注意:

修改后的主题需要中文WordPress工具箱Plugin的支持。原作者为桑葚,本blog中已经将其进行改进。

请注意将上面代码中的”/?”改成”<?”,”?/”改成”?>”。

下载:

Download: WordPress-Chinese-Kit.zip  WordPress-Chinese-Kit.zip (2.7 KiB, 1,089 hits)

Download: Into-The-Ocean-Modified-by-Tisan.zip  Into-The-Ocean-Modified-by-Tisan.zip (99.2 KiB, 1,049 hits)

===================================

English Instruction:

This modified theme is to my dear friend: Helena.

Changing Log:

1, Change the recent-posts function

The Into-The-Ocean uses the_content_css to display recent posts. This function counts word number divided by space. However, in Chinese article, there is rarely space. Thus, the_content_css acts not well in Chinese WordPress Site.

We should write another function to update this bug. Add following function in feed.php at

INCLUDES directory.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
function the_chinesecontent_rss($more_link_text='(more...)', $stripteaser=0, $more_file='', $cut = 0, $encode_html = 0) {
 $content = get_the_content($more_link_text, $stripteaser, $more_file);
 $content = apply_filters('the_content_rss', $content);
 if ( $cut && !$encode_html )
  $encode_html = 2;
 if ( 1== $encode_html ) {
  $content = wp_specialchars($content);
  $cut = 0;
 } elseif ( 0 == $encode_html ) {
  $content = make_url_footnote($content);
 } elseif ( 2 == $encode_html ) {
  $content = strip_tags($content);
 }
 if ( $cut ) {
  $excerpt =substr($content,0,$cut);
  $excerpt = utf8_trim($excerpt);
  $content = $excerpt.'...';
 }
 $content = str_replace(']]>', ']]>', $content);
 echo $content;
}

Then change the codes index.php from

1
/?php the_content_rss('',FALSE,'',100);?/</p>

to

1
/?php the_chinesecontent_rss('',FALSE,'',100);?/</p>

If you are not using WordPress Chinese Kit, you also should add following function. But if you are, it’s forbidden to do this.

1
2
3
4
5
6
7
8
9
10
11
12
function utf8_trim($str) {

 $len = strlen($str);

 for ($i=strlen($str)-1; $i>=0; $i-=1){
  $hex .= ' '.ord($str[$i]);
  $ch = ord($str[$i]);
        if (($ch & 128)==0) return(substr($str,0,$i));
  if (($ch & 192)==192) return(substr($str,0,$i));
 }
 return($str.$hex);
}

2, Change the width

From 100% to fixed 1004px(IE) and 1008px(FireFox).

3, Change the footer.php

Add the recent comments. For this, you need the plugin: WordPress Chinese Kit.

4, Change some foot size

5, Change some BOX properties

To make clean_archives_reloaded work well.

6, Change header.php

There is no wp_head() at header.php of Into-The-Ocean. It will result in the invalidation of some plugins.

please add

1
/?php wp_head(); ?/

before:

1
</head>

7,Change comment.php

Comment is not operable in Into-The-Ocean. I think this is because of the WordPress Version.

Please find following codes at comment.php in Into-The-Ocean directory:

1
2
3
4
  <p><textarea name="comment_box" id="comment_box" cols="100%" rows="10" tabindex="4"></textarea></p>
 
  <p><input name="submit" type="submit" id="submit" tabindex="5" value="Submit" />
  <input type="hidden" name="comment_post_ID" value="/?php echo $id; ?/" /></p>

And change to:

1
2
3
4
  <p><textarea name="comment" id="comment" cols="100%" rows="10" tabindex="4"></textarea></p>
 
  <p><input name="submit" type="submit" id="submit" tabindex="5" value="Submit Comment" />
  <input type="hidden" name="comment_post_ID" value="/?php echo $id; ?/" /></p>

Note:

This modified theme needs the WordPress Chinese Kit. The author is 桑葚. The downloadable file in this page have been updated by me.

Make sure you have change the code above “/?” to “<?” and “?/” to “?>”.

Download:

Download: WordPress-Chinese-Kit.zip  WordPress-Chinese-Kit.zip (2.7 KiB, 1,089 hits)

Download: Into-The-Ocean-Modified-by-Tisan.zip  Into-The-Ocean-Modified-by-Tisan.zip (99.2 KiB, 1,049 hits)

Leave a Comment