一聚教程网:一个值得你收藏的教程网站

热门教程

Drupal 7 实现上一篇下一篇的简单方法

时间:2022-06-25 16:37:07 编辑:袖梨 来源:一聚教程网

在模板/sites/all/themes/liuzhiliang.com/template.php文件上加个函数

 代码如下 复制代码

/**
 * myNodePrevNext
 * 文章上一篇下一篇
 * $nid - 节点id
 * $type - 节点类型
 */
function myNodePrevNext($nid, $type)
{
    $output = '

    ';

        $sql_previous = "SELECT n.nid, n.title, url.alias "
                      . "FROM {node} AS n "
                      . "LEFT JOIN {url_alias} AS url "
                      . "ON concat('node/',n.nid)=url.source "
                      . "WHERE n.nid < :nid AND n.type = :type "
                      . "ORDER BY n.nid DESC "
                      . "LIMIT 0, 1";

        $result_previous = db_query($sql_previous, array(':nid' => $nid, ':type' => $type));

        $strings = array();

        foreach ($result_previous as $data)
        {
            $data->url = ($data->alias) ? $data->alias : '/node/' . $data->nid;

            $output .= '

  • 上一篇:'
                    . ''
                    . $data->title
                    . '
    '
                    . '
  • ';
        }

        $sql_next = "SELECT n.nid, n.title, url.alias "
                  . "FROM {node} AS n "
                  . "LEFT JOIN {url_alias} AS url "
                  . "ON concat('node/',n.nid)=url.source "
                  . "WHERE n.nid > :nid AND n.type = :type "
                  . "ORDER BY n.nid ASC "
                  . "LIMIT 0, 1";
        $result_next = db_query($sql_next, array(':nid' => $nid, ':type' => $type));

        $strings = array();

        foreach ($result_next as $data)
        {
            $data->url = ($data->alias) ? $data->alias : '/node/' . $data->nid;

            $output .= '

  • 下一篇:'
                    . ''
                    . $data->title
                    . '
    '
                    . '
  • ';
        }

        $output .= '

';

    return $output;
}

再到/sites/all/themes/liuzhiliang.com/templates/node.tpl.php加上下面这段代码,具体位置看自己喜欢,我是在文章底部显示,所以在回在了

>后面

 代码如下 复制代码


 


    nid, $node->type); // 上下篇 ?>
 

原文来自:啊亮博客 http://liuzhiliang.com/node/63