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文件上传激活就可以了,不过我在后台看不见插件,卸载麻烦,考虑清楚再安装。 小弟不才,不正之处,还望指点一二。 多谢兄弟分享! 谢谢分享,不过最好把原文地址贴出来,以供参考! 这个插件很好。。。收藏 原来还有这种插件:handshake 收藏了,以后用得着、 好东西,收藏了 这也能采集呀,不错 直接用css样式把超长的部分隐藏就好了,这样搜索引擎索引完整,界面又不会错乱 thanks for you share 好东西,收藏了 很不错的东西值得收藏
页:
[1]