dedecms列表页文章摘要字数的设置方法
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>本文实例讲述了dedecms列表页文章摘要字数的设置方法。分享给大家供大家参考。具体实现方法如下:</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
在Dedecms系统中,文章摘要(可以通过infolen或description相关标签调用)被设置了字数上限为250字符,设置上限的主要目的是减少数据库的冗余,保证网站良好的性能,因此,如果对简介内容不设置上限显然不合理,但是如果可以自由控制这一上限,那么将对网页内容布局带来积极作用,在网页设计过程中,往往需要在频道列表页面调用到文章摘要,如果可以有效控制文章摘要的字数,那么就可以使得页面布局很灵活.</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
在Dedecms中,在列表页调用文章摘要的方法主要有:</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
1:</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
2:</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
3:</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
4:</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
第 1、2种方法是直接调用文章摘要,在调用的字数问题上,当使用时,可以在{dede:arclist infolen=' ' }{/dede:arclist}中,设置调用摘要的字符数(最高可设置为系统设置的250);如果使用,则直接使用后台设置的摘要字符上限。显然,这两种方式都很被动,灵活性太差。</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
第3、4种方法通过function函数实现了对文章摘要显示字符的灵活调整。当然,在没有修改文章摘要内容字符上限时,这4个方法的差异并不大。但是,下面我们来说如何修改这一上限值,就可以体现出 这一方式的重要性。</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
在Dedecms中,与文章摘要相关的php文件主要有:</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
/dede/archives_add.php <br>
/dede/archives_edit.php <br>
/dede/article_add.php <br>
/dede/article_edit.php <br>
/dede/article_description_main.php <br>
//phpfensi.com </p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
在 add页面,有一句话是:</p>
<div class="msgheader" style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<div class="right">
<span><u>复制代码</u></span>
</div>
代码如下:</div>
<div class="msgborder" id="phpcode8" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
$description = cn_substrR($description,$cfg_auot_description);</div>
<p>
<span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>这句话实现了</span></p>
<p>
</p>
<div class="msgheader" style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<div class="right">
<span><u>复制代码</u></span>
</div>
代码如下:</div>
<div class="msgborder" id="phpcode9" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
</div>
<span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>这一功能。因为这一语句确实有利于页面布局,因此我们在实验中没有修改。</span>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
在 edit页面,有一句话是:</p>
<div class="msgheader" style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<div class="right">
<span><u>复制代码</u></span>
</div>
代码如下:</div>
<div class="msgborder" id="phpcode10" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
$description = cn_substrR($description,250);</div>
<span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>这句话中出现了一个熟悉的字符数“250”,这就是系统设置的文章摘要字符数的上限值。 如果是gbk编码则显示出来的就是125个字。如果是utf-8编码则是81个字。显然,我们要突破文章摘要字符数上限,肯定得拿它开刀了。是的,这里修改“250”为其他值即可,例如“500”,这里不推荐设置得过高,一个是在列表页没必要展示太多内容,展示太多内容不如直接用body了,另一个是避免数据库产生冗余.</span>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
完成上面的修改还不够,还需要修改article_description_main.php</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
在 article_description_main.php页面,找到“if($dsize>250) $dsize = 250;”语句,这里限制了在后台自动获取摘要的字符数。把这里的“250”修改为“500”即可,也就是和之前修改的字符数一致即可,如果你确认你的每一条文章都是手动添加,手动完成摘要获取就不需要修改这个文件了,自动摘要获取主要还是给大量文章和采集准备的.</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
最后,登录后台,在系统-系统基本参数-其它选项中,自动摘要长度,改成500即可,也就是和之前修改的字符数一致即可.</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
完成上述修改后,我们再到频道列表页,通过标签调用即可,示例标签如下:<br>
</p>
<div class="msgheader" style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<div class="right">
<span><u>复制代码</u></span>
</div>
代码如下:</div>
<div class="msgborder" id="phpcode11" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
{dede:list typeid='' row='5' titlelen='100' orderby='new' pagesize='5'} <br>
<br>
... <br>
{/dede:list}</div>
<br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>通过以上方式,我们就实现了调用的文章摘要字符为500字符,完全突破了文章摘要250字符的系统限制,为网页布局提供了更加广阔的空间.</span>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
希望本文所述对大家的dedecms建站有所帮助。</p>
頁:
[1]