首页前端开发HTMLTE获取上一篇/下一篇的链接

TE获取上一篇/下一篇的链接

时间2023-04-25 02:39:01发布访客分类HTML浏览608
导读:文章上一篇与下一篇调用代码:<?php $this->thePrev( ; ?> <?php $this->theNext( ; ?>或者<?php $this->thePrev('上一篇 :...

文章上一篇与下一篇调用代码:

?php $this->
    thePrev();
     ?>
     ?php $this->
    theNext();
     ?>
    

或者

?php $this->
    thePrev('上一篇 : %s', '没有上一篇');
     ?>
    
?php $this->
    theNext('下一篇 : %s', '没有下一篇');
     ?>
    

这样的会输出同时文章的标题和链接,不是很利于加样式。 不过1.0版的typecho,已经支持更灵活的上下文输出:

$this->
    thePrev($format = '%s', $default = NULL, $custom = array(
'title' =>
     '',
'tagClass' =>
     ''
));
    

$custom 数组部分即为自定义内容,目前支持给上下文链接添加自定义的 CSS 类名、及输出文字,文字部分支持 html 代码:

$this->
    thePrev('%s', NULL, array('title' =>
     'span>
    上一篇/span>
    ', 'tagClass' =>
     'prev-content'));

上面的代码会输出:

a class="prev-content" href="{
permalink}
" title="{
title}
    ">
    span>
    上一篇/span>
    /a>

老版本(亲测:其实1.0版这么用也是可以的)

/**
* 显示下一篇
*
* @access public
* @param string $default 如果没有下一篇,显示的默认文字
* @return void
*/
function theNext($widget, $default = NULL)
{
    
$db = Typecho_Db::get();
    
$sql = $db->
    select()->
    from('table.contents')
->
    where('table.contents.created >
     ?', $widget->
    created)
->
    where('table.contents.status = ?', 'publish')
->
    where('table.contents.type = ?', $widget->
    type)
->
    where('table.contents.password IS NULL')
->
    order('table.contents.created', Typecho_Db::SORT_ASC)
->
    limit(1);
    
$content = $db->
    fetchRow($sql);

 
if ($content) {
    
$content = $widget->
    filter($content);
    
$link = 'a href="' . $content['permalink'] . '" title="' . $content['title'] . '">
    下一篇/a>
    ';
    
echo $link;

}
 else {
    
echo $default;

}

}
 
/**
* 显示上一篇
*
* @access public
* @param string $default 如果没有下一篇,显示的默认文字
* @return void
*/
function thePrev($widget, $default = NULL)
{
    
$db = Typecho_Db::get();
    
$sql = $db->
    select()->
    from('table.contents')
->
    where('table.contents.created  ?', $widget->
    created)
->
    where('table.contents.status = ?', 'publish')
->
    where('table.contents.type = ?', $widget->
    type)
->
    where('table.contents.password IS NULL')
->
    order('table.contents.created', Typecho_Db::SORT_DESC)
->
    limit(1);
    
$content = $db->
    fetchRow($sql);
 
if ($content) {
    
$content = $widget->
    filter($content);
    
$link = 'a href="' . $content['permalink'] . '" title="' . $content['title'] . '">
    上一篇/a>
    ';
    
echo $link;

}
 else {
    
echo $default;

}

}
    

调用代码:

?php thePrev($this);
     ?>
     和 ?php theNext($this);
     ?>
    

文章参考

http://t.160.me/33.html

声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!

csshtmltypecho数组

若转载请注明出处: TE获取上一篇/下一篇的链接
本文地址: https://pptw.com/jishu/7877.html
博客被人丢进了雷姆 自定义Typecho加密文章的Html结构

游客 回复需填写必要信息