漩涡's Archivers

From aarwwefdds on 2010-10-09 18:54:01

Polished主题,文章摘要只有“...”和预览图片无法显示的解决方案

前几天帮朋友做WordPress,朋友用的是Polished主题,分别遇上了如下两个问题:


1、即使增加图片,首页的摘要也没有图片


2、摘要部分为“...”


首先来说说第一个的解决办法



SyntaxHighlighter.all();


进入外观——Polished theme options——general setting


找到Grab the first post image,改为this is enable即可【或者在文章时注意右下角的“特色图片”,手动添加特色图片也行,稍微麻烦点】


第二个我百思不得其解,在主题设置里翻了半天愣是没见,只能从代码上下手了


首先看到featured.php的代码,发现输出摘要部分是这样的:


<div class="slide">
<h1><?php echo $arr[$i]["title"]; ?></h1>
<br class="clear" />
<?php print_thumbnail($arr[$i]["thumb"], $arr[$i]["use_timthumb"], $arr[$i]["fulltitle"] , $width, $height,'featured_img'); ?>
<?php echo $arr[$i]["excerpt"];?>


<span class="readmore_g"><a href="<?php echo $arr[$i]["permalink"]; ?>"> <?php _e('Read More','Polished') ?></a></span>
</div>
<?php }; ?>
</div>

 


<?php echo $arr[$i]["excerpt"];?>

看到这句,然后往前翻


<?php
$ids = array();
$arr = array();
$i=1;

$width = 177;
$height = 177;

$width2 = 35;
$height2 = 35;

$featured_cat = get_option('polished_feat_cat');
$featured_num = get_option('polished_featured_num');

if (get_option('polished_use_pages') == 'false') query_posts("showposts=$featured_num&cat=".get_catId($featured_cat));
else {
global $pages_number;
if (get_option('polished_feat_pages') <> '') $featured_num = $pages_number - count(get_option('polished_feat_pages'));
else $featured_num = $pages_number;

query_posts(array
('post_type' => 'page',
'orderby' => 'menu_order',
'order' => 'ASC',
'post__not_in' => get_option('polished_feat_pages'),
'showposts' => $featured_num
));
};

while (have_posts()) : the_post();

$arr[$i]["title"] = truncate_title(22,false);
$arr[$i]["title2"] = truncate_title(25,false);
$arr[$i]["fulltitle"] = truncate_title(250,false);
$arr[$i]["excerpt"] = truncate_post(350,false);//注意这里,调用truncate_post函数

//$arr[$i]["excerpt"] = the_content('');
$arr[$i]["permalink"] = get_permalink();
$arr[$i]["postinfo"] = __("Posted by", "Polished")." ". get_the_author_meta('display_name') . __(' on ','Polished') . get_the_time(get_option('polished_date_format'));

$arr[$i]["thumbnail"] = get_thumbnail($width,$height,'featured_img',$arr[$i]["fulltitle"]);
$arr[$i]["thumb"] = $arr[$i]["thumbnail"]["thumb"];
$arr[$i]["use_timthumb"] = $arr[$i]["thumbnail"]["use_timthumb"];

$arr[$i]["thumbnail2"] = get_thumbnail($width2,$height2,'',$arr[$i]["fulltitle"]);
$arr[$i]["thumb2"] = $arr[$i]["thumbnail2"]["thumb"];

$i++;
$ids[]= $post->ID;
endwhile; wp_reset_query(); ?>

然后又继续找,找到custom_functions.php,开头就是这个函数【放在这里难道是故意让人首先看到?】


function truncate_post($amount,$echo=true) {
global $post;

$truncate = $post->post_content;
if ( strlen($truncate) <= $amount ) $echo_out = ''; else $echo_out = '...';//如果文章长度大于之前传进来的$amount(350字),则在文章后放上“...”

$truncate = apply_filters('the_content', $truncate);//启用本函数进行过滤
$truncate = preg_replace('@<script[^>]*?>.*?</script>@si', '', $truncate);//将script无视(去掉)
$truncate = preg_replace('@<style[^>]*?>.*?</style>@si', '', $truncate);//将style无视(去掉)【想的挺周全】
$truncate = strip_tags($truncate);//去除一些特殊标签
if ($echo_out == '...') $truncate = substr($truncate, 0, strrpos(substr($truncate, 0, $amount), ' '));//这句是重点,如果有输出“...”【意思是文章字数大于$amount】。则截取从开头到$amount[第350字]之间的最后一个空格【空格啊,注意是空格!】 else $truncate = substr($truncate, 0, $amount);//如果没有“...”则直接输出

if ($echo) echo $truncate,$echo_out;//如果要求回显【默认】,否则以字符串输出
else return ($truncate . $echo_out);
}

问题就出在


 


if ($echo_out == '...') $truncate = substr($truncate, 0, strrpos(substr($truncate, 0, $amount), ' '));

里了,因为截取的是空格【西欧语言里不可能没有空格】,而中文字里不一定会有空格,所以就杯具了


中文字里不可能没有什么?逗号!,直接将这句改成:


 


if ($echo_out == '...') $truncate = substr($truncate, 0, strrpos(substr($truncate, 0, $amount), ','));

即可


done~


查看完整版本: Polished主题,文章摘要只有“...”和预览图片无法显示的解决方案

From 毕扬 on 2010-10-09 18:56:02

沙发是我的 :gudu

From aarwwefdds on 2010-10-09 19:54:16

谢谢撒花 不过貌似没有显示出最新文章?

From 妊娠纹能去掉吗 on 2010-10-10 13:12:53

过来看看 看看楼主~!

From www.bvod.info on 2010-10-11 18:42:17

很漂亮啊....大家也来我的小站看看吧!免费在线电影 保证你大饱眼福www.bvod.info

From 测试用的 on 2010-10-12 12:56:57

你好,很久没来这了!

From 网页游戏大全 on 2010-10-12 21:23:30

看看这种类型的游戏。。。。

From 凡客礼品卡 on 2010-10-12 21:36:49

博主的文章写的不错!!~~

From 打酱油的 on 2010-10-14 13:36:05

访问速度很快啊

From 打酱油的 on 2010-10-14 13:37:44

闪啦

From 功夫派角色介绍 on 2010-10-15 07:40:39

文章不错,占个位置先

From honeyfish on 2010-11-16 00:50:24

请问博主,我所用的主题和你的情况是一样的,但是用了你的方法不奏效。只有减少博文字数,才不显示"..."。现在不知改哪里了,请赐教。

From aarwwefdds on 2010-11-16 13:58:30

可能你用的是半角逗号呢 if ($echo_out == '...') $truncate = substr($truncate, 0, strrpos(substr($truncate, 0, $amount), ',')); 这么改就好啦

From honeyfish on 2010-11-16 15:44:38

嘿。。。好了,我开始的时候是在本地测试的,没反应,刚才在服务器上直接试,就OK了。谢谢!

From honeyfish on 2010-11-16 16:05:53

再问博主,如何更改摘要的字数限制呢? FOMATTING.PHP改了没用。

From aarwwefdds on 2010-11-17 13:39:53

函数用法:truncate_post([限制字数],[回显true or false]) 因为是按照逗号截取,所以实际截取摘要不一定符合传入函数的限制字数,而是等于0~限制字数之前的最后一个逗号 如果修改不成功,把代码贴一下

From honeyfish on 2010-11-17 20:00:28

能MAIL我你的联系方式么?

From aarwwefdds on 2010-11-18 18:37:29

webmaster@本站域名

From 千家乐 on 2010-11-18 23:51:23

不错的文章哈,踩踩啦!祝博主永远快乐!

From omgR on 2010-11-25 17:05:53

膜拜一下 非常感谢 正在找

From fishbc on 2010-12-13 14:17:01

非常实用!博客不错!

From 新民智 on 2011-01-16 11:00:58

已给楼主的邮箱 webmaster@本站域名 发了求助邮件,等您回复!急!

From Zmsky on 2011-02-12 16:04:28

对了,那个代码插件名字叫啥来着?

From Jackie on 2011-04-26 11:54:54

解决了我大问题啊,我一直在折腾类似主题的这段代码,但一直看不怎么懂,竟然是按照空格截断..

From 雨宫优子 on 2011-04-26 22:05:07

嗯~很荣幸~

From 雨宫优子 on 2011-04-26 22:05:32

额?哪个?

From 幸运随行 on 2011-05-01 19:09:51

很好很强大!

From 海是倒过来的天 on 2011-05-28 23:57:46

又是神马的代码。。。

From andychao on 2011-07-26 01:17:24

刚好解决了我的问题,谢谢!!

From Cocomo on 2011-12-11 11:11:32

有用到,非常感谢!

From ThWa on 2012-01-12 04:41:09

改成中文“,”的话,貌似英文文章的摘要又会变成...。能不能同时处理呢

From 雨宫优子 on 2012-01-15 01:08:14

那就只能多加个判断了,先优先使用中文提取法,如果中文提取出来的是“...”。那么则采用英文提取法

Tags: Polished, Polished主题, WordPress


©漩涡网络安全实验室