/**
* 在Node 里添加上一页下一页链接函数 请参考 http://drupal.org/node/37767 设计到两个函数, next_node和previous_node 在使用的主题下面 template.php文件里添加下面两个函数,无此文件可以先建立、>
*
* @参数 $append_text 附加的一些文本
*
*
*/
function next_node($node, $next_node_text=NULL, $prepend_text=NULL, $append_text=NULL)// 四个参数,后三个默认为空,在引用的时候根据需要可以赋值
{
$query = db_rewrite_sql("SELECT nid, title FROM {node} WHERE created > '%s' AND status=1 and promote=1 AND type='%s' ORDER BY created ASC LIMIT 1", "node", "nid");
// 得到当前node的是时间,然后判断大于这篇文章的时间文章,并且只读取一条数据,还有一点是同内容类型的文章$node->type
$result = db_query($query, $node->created, $node->type);
$next_node = db_fetch_object($result);
if(!$next_node_text) //如果next_node_text变量没有赋值,为空的情况下,那就是用node 标题作为衔接标题
{
$next_node_text = $next_node->title;
}
if($next_node->nid!=NULL)//如果$next_node->nid不为空情况下,也就是没有了
{
return $prepend_text.l($next_node_text, 'node/'.$next_node->nid, array('title'=>'Go to the next post "'.$next_node_text.'"', 'class'=>'goto-previous-node')).$append_text;
//放回$prepend_text赋给的值加上一个衔接l(标题,'衔接地址','其他属性:title.class')只要使用l()函数来处理,最后加上一个$append_text
}
else // 没有.
{
return NULL;//返回空
}
}
/**
* @参数 $node
*
* @参数 $previous_node_text
*
*
* @参数 $prepend_text
*
* @参数 $append_text
*
*
*/
function previous_node($node, $previous_node_text=NULL, $prepend_text=NULL, $append_text=NULL)
{
$query = db_rewrite_sql("SELECT nid, title FROM {node} WHERE created < '%s' AND status=1 and promote=1 AND type='%s' ORDER BY created DESC LIMIT 1", "node", "nid");
//上一条信息也是根据当前的node时间判断,如果小于当前时间的node,那就是前面一条了。
$result = db_query($query, $node->created, $node->type);
$previous_node = db_fetch_object($result);
if(!$previous_node_text) // 如果没有赋值,就是用title.
{
$previous_node_text = $previous_node->title;
}
if($previous_node->nid!=NULL)
{
return $prepend_text.l($previous_node_text, 'node/'.$previous_node->nid, array('title'=>'Go to the previous post "'.$previous_node_text.'"', 'class'=>'goto-previous-node')).$append_text;
}
else // 这条node,前面没有信息了。
{
return NULL;
}
}
?>
然后再node.tpl.php里,把下面代码放入你想要的位置:
';
if($previous_node_link && $next_node_link)
{
print $previous_node_link.' | '.$next_node_link;
}
else if($previous_node_link)
{
print $previous_node_link;
}
else if($next_node_link)
{
print $next_node_link;
}
print '
评论
这个添加上一页和下一页的地方,如何能实现在特定的一些nod
这个添加上一页和下一页的地方,如何能实现在特定的一些node里添加啊?而不是在所有的node里加这个。
我新建了一个内容类型 view显示的是这个内容类型的东西,然后当添加上下页后,别的内容类型的node也加了,这是不想实现的。不知道这个能不能实现?
可以通过 $node->type
可以通过
$node->type 来判断。
在node.tpl.php 模板里
发表新评论