cqxing007 发表于 2012-2-8 13:06:59

wprobot 采集amazon 标题过长的解决办法(插件)

在一Blog发现的插件,作者把源码给出来了,

原文:

Truncate Titles
Let’s say you’ve written lots of posts with lengthy titles. But now you’re switching to a theme that doesn’t handle long titles well. Copy this into a file, name it truncateTitle.php (or whatever.php), upload to your plugins directory, and activate it in the usual way. Don’t leave any blank lines or spaces before or after this code (or you’ll get an error).<?php
/*
Plugin Name: KB Truncate Title
Plugin URI: http://adambrown.info/b/widgets/category/custom/
Description: Truncates titles so they don't break your theme
Version: 1.0
Author: Adam R. Brown
Author URI: http://adambrown.info/
*/

define('KB_TRUNCATE_TITLE', 50); // change 50 to max number of characters to allow

function kb_truncateTitle($title){
        if (!is_int( KB_TRUNCATE_TITLE ) || 1>KB_TRUNCATE_TITLE )
                return $title;
        // rather than just use substr, let's make sure we cut it at the end of a word
        $arr = explode(' ', $title);
        $out = '';
        $count = 0;
        foreach( $arr as $str ){
                $count += ( strlen($str) + 1); // +1 is for the space we removed
                if ($count > KB_TRUNCATE_TITLE)
                        break;
                $out .= $str . ' ';
        }
        // make sure we got SOMEthing
        if (!$out)
                $out = $arr;
        return $out;
}This entry was written by Adam on January 7, 2008. This entry was posted in Custom. Bookmark the permalink. Both comments and trackbacks are currently closed.

这个插件的好处是不会把单词从中间间断,它会在接近限定的单词数范围内把最后一个单词截断。
用Google翻译也都能知道这大概说什么,不过我顺便说下吧,新建一个文件truncateTitle.php,把代码复制进去,注意不要有空格,要不会出错,压缩成zip文件上传激活就可以了,不过我在后台看不见插件,卸载麻烦,考虑清楚再安装。 小弟不才,不正之处,还望指点一二。

xavier 发表于 2012-2-8 20:09:23

多谢兄弟分享!

lauwa 发表于 2012-2-9 13:49:01

谢谢分享,不过最好把原文地址贴出来,以供参考!

termjoy 发表于 2012-2-9 14:24:34

这个插件很好。。。收藏

hlzone 发表于 2012-2-9 16:41:04

原来还有这种插件:handshake

anisor 发表于 2012-2-28 09:43:45

收藏了,以后用得着、

bnm765333 发表于 2012-3-4 10:42:58

好东西,收藏了

haizhizuan 发表于 2012-3-30 17:48:32

这也能采集呀,不错

kevin 发表于 2012-4-3 11:32:35

直接用css样式把超长的部分隐藏就好了,这样搜索引擎索引完整,界面又不会错乱

vertiefung 发表于 2012-4-26 13:16:37

thanks for you share

sola128 发表于 2012-5-2 16:16:53

好东西,收藏了

zhangxingbo 发表于 2012-5-15 09:49:42

很不错的东西值得收藏
页: [1]
查看完整版本: wprobot 采集amazon 标题过长的解决办法(插件)