sablog上下主题优化

发布人:blankyao  时间:2007-11-03 00:51  来源: blankyao.cn   查看: 421次   TAG: sablog  sablog优化 

你是否厌倦了阅读文章时下面显示的"‹‹ 上一篇 | 下一篇 ››",其实搜索引擎也厌倦了这些内容(模仿水水),那就把这单调的"‹‹ 上一篇 | 下一篇 ››"改为上下篇的文章的标题吧!

对于seo来说有很好的导航作用,这个是很重要的!

看到水水写的这个Discuz!上下主题细节优化得到了启发,于是写了这个适用与sablog的!


你是否厌倦了阅读文章时下面显示的"‹‹ 上一篇 | 下一篇 ››",其实搜索引擎也厌倦了这些内容,那就把这单调的"‹‹ 上一篇 | 下一篇 ››"改为上下篇的文章的标题吧!

对于seo来说有很好的导航作用,这个是很重要的!

首先在./global.php里插入这个函数

复制内容到剪贴板
PHP代码:
function bottom_title($action,$articleid){&nbsp; &nbsp; <BR>&nbsp; &nbsp$id=($action=="next"?++$articleid:--$articleid);&nbsp; &nbsp; <BR>&nbsp; &nbsp; global $DB,$db_prefix;&nbsp; &nbsp; <BR>&nbsp; &nbsp$title=$DB-&gt;fetch_one_array("SELECT title,visible from {$db_prefix}articles WHERE&nbsp; &nbsp;articleid='".$id."'");&nbsp; &nbsp; <BR>&nbsp; &nbsp$title=$title==0?""$title['visible']==0?bottom_title($action,$articleid)title['title']);&nbsp; &nbsp; <BR>&nbsp; &nbsp; return $title;&nbsp; &nbsp; <BR>}&nbsp; &nbsp;

这个函数是整个功能的核心

下一步就是来调用这个函数了

在./index.php里”显示文章“的那一块做如下修改[code]// 显示文章   
elseif ($_GET['action'] == 'show') {   
    session_start();   
    $articleid = intval($_GET['id']);   
    // 获取文章信息      
    $article = $DB->fetch_one_array("SELECT a.*,c.name as cname,u.username   
        FROM {$db_prefix}articles a   
        LEFT JOIN {$db_prefix}categories c ON c.cid=a.cid   
        LEFT JOIN {$db_prefix}users u ON a.uid=u.userid   
        WHERE a.visible='1' AND articleid='$articleid'");   
    if (!$article) {   
        message('记录不存在', './');   
    }   
    if ($_POST['readpassword'] && ($article['readpassword'] == addslashes($_POST['readpassword']))) {   
        $_SESSION['readpassword_'.$articleid] = addslashes($_POST['readpassword']);   
    }   
   
   
//加入下面两句,就是为了调用   
//显示上篇下篇的标题   
$pre=bottom_title("pre",$articleid);   
$next=bottom_title("next",$articleid);   [/code]在这里调用结束了,下一步就是输出到模板里了

在./template/你的模板名字/show.php中找到“上一篇”和“下一篇”,分别修改为$pre和$next就可以了!

OK,就这样了,这个功能实现挺简单的,在速度上要比默认的慢一些,但是如果流量不是巨大的那种站也体会不到慢,毕竟只是多了个查询而已,而这个功能对seo可是很重要的!

本月热门