EEfaq论坛-赚客自留地

 找回密码
 免费注册
查看: 2652|回复: 11

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

  [复制链接]
发表于 2012-2-8 13:06:59 | 显示全部楼层 |阅读模式
在一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).
  1. <?php
  2. /*
  3. Plugin Name: KB Truncate Title
  4. Plugin URI: http://adambrown.info/b/widgets/category/custom/
  5. Description: Truncates titles so they don't break your theme
  6. Version: 1.0
  7. Author: Adam R. Brown
  8. Author URI: http://adambrown.info/
  9. */

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

  11. function kb_truncateTitle($title){
  12.         if (!is_int( KB_TRUNCATE_TITLE ) || 1>KB_TRUNCATE_TITLE )
  13.                 return $title;
  14.         // rather than just use substr, let's make sure we cut it at the end of a word
  15.         $arr = explode(' ', $title);
  16.         $out = '';
  17.         $count = 0;
  18.         foreach( $arr as $str ){
  19.                 $count += ( strlen($str) + 1); // +1 is for the space we removed
  20.                 if ($count > KB_TRUNCATE_TITLE)
  21.                         break;
  22.                 $out .= $str . ' ';
  23.         }
  24.         // make sure we got SOMEthing
  25.         if (!$out)
  26.                 $out = $arr[0];
  27.         return $out;
  28. }
复制代码
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文件上传激活就可以了,不过我在后台看不见插件,卸载麻烦,考虑清楚再安装。 小弟不才,不正之处,还望指点一二。
发表于 2012-2-8 20:09:23 | 显示全部楼层
多谢兄弟分享!
回复 支持 反对

使用道具 举报

发表于 2012-2-9 13:49:01 | 显示全部楼层
谢谢分享,不过最好把原文地址贴出来,以供参考!
回复 支持 反对

使用道具 举报

发表于 2012-2-9 14:24:34 | 显示全部楼层
这个插件很好。。。收藏
回复 支持 反对

使用道具 举报

发表于 2012-2-9 16:41:04 | 显示全部楼层
原来还有这种插件
回复 支持 反对

使用道具 举报

发表于 2012-2-28 09:43:45 | 显示全部楼层
收藏了,以后用得着、
回复 支持 反对

使用道具 举报

发表于 2012-3-4 10:42:58 | 显示全部楼层
好东西,收藏了
回复 支持 反对

使用道具 举报

发表于 2012-3-30 17:48:32 | 显示全部楼层
这也能采集呀,不错
回复 支持 反对

使用道具 举报

发表于 2012-4-3 11:32:35 | 显示全部楼层
直接用css样式把超长的部分隐藏就好了,这样搜索引擎索引完整,界面又不会错乱
回复 支持 反对

使用道具 举报

发表于 2012-4-26 13:16:37 | 显示全部楼层
thanks for you share
回复 支持 反对

使用道具 举报

发表于 2012-5-2 16:16:53 | 显示全部楼层
好东西,收藏了
回复 支持 反对

使用道具 举报

发表于 2012-5-15 09:49:42 | 显示全部楼层
很不错的东西值得收藏
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

QQ|联系我们|Archiver|手机版|小黑屋|EEfaq论坛

GMT+8, 2024-4-29 14:59

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表