DEDECMS自定义模块之文章上下篇

来源:互联网 发布:.lol域名无法备案 编辑:程序博客网 时间:2024/06/08 03:59
1、$aid文章ID
2、$typeid文章所属栏目ID
3、$act当前文章所属栏目的标识
4、$ksOne文章一级栏目名称
5、$ksTwo文章二级栏目名称

 /*********************获取当前文章栏目ID**************************/ 
$ksxxListArr=array("experience" , "outline" , "quesBase" , "quesPr" , "pracBase" , "pracPr");//定义栏目列表
if((!isset($_GET['act'])) || ($_GET['act']=="") || (!in_array($_GET['act'], $ksxxListArr))){
 ShowMsg('非法参数,请勿提交!', '-1');
 exit(); 
}else{ 
 $act = $_GET['act'];
}
$ksxxArr = array( //定义栏目列表一级和二级名称和栏目ID
  'experience' => array("复习指导","考试经验",236), 
  'outline' => array("复习指导","考试大纲",235), 
  'quesBase' => array("试题中心","经济学基础",239),  
  'quesPr' => array("试题中心","初级会计实务",237),  
  'pracBase' => array("每日一练","经济学基础",240), 
  'pracPr' => array("每日一练","初级会计实务",238) 
 );
 foreach($ksxxArr as $ksxxkey => $ksxxval){
  if($ksxxkey==$act){
   $ksOne=$ksxxval[0];
   $ksTwo=$ksxxval[1]; 
   $typeid=$ksxxval[2]; 
  }
 }
/*********************获取当前文章栏目ID**************************/ 
if(!isset($_GET['id']) || empty($_GET['id'])){
 ShowMsg('找不到页面!', '-1');
 exit();  
}
$aid=$_GET['id'];
$aid=intval($aid);
//获取当前文章
$arc= $dsql->GetOne( "select a.title , a.id , a.pubdate , a.source , b.body from 
`#@__archives` a LEFT JOIN `#@__addonarticle` b ON a.id = b.aid WHERE b.aid= '{$aid}' AND a.arcrank!='-2' ORDER BY a.pubdate DESC"); 
/*********************获取当前文章栏目ID**************************/ 
  
/****************定义方法获取上下篇***************************/
 $PreNext= array();
 if(count($PreNext)<2)
 {
  $preR =  $dsql->GetOne("Select id From 
`#@__arctiny` where id<'{$aid}' And arcrank>-1 And typeid='{$typeid}' order by id desc");
  $nextR = $dsql->GetOne("Select id From 
`#@__arctiny` where id>'{$aid}' And arcrank>-1 And typeid='{$typeid}' order by id asc");
  $pre = (is_array($preR) ? " where id={$preR['id']} " : ' where 1>2 ');
  $next = (is_array($nextR) ? " where id={$nextR['id']} " : ' where 1>2 ');
  $query = "Select id , title from 
`#@__archives` ";
  $preRow = $dsql->GetOne($query.$pre);
  $nextRow = $dsql->GetOne($query.$next);
  if(is_array($preRow))
  {
   $PreNext['pre'] = "上一篇:<a href='article.php?act=".$act."&id=".$preRow['id']."'>{$preRow['title']}</a> ";
  }
  else
  {
   $PreNext['pre'] = "上一篇:没有了!";
  }
  if(is_array($nextRow))
  {
   $PreNext['next'] = "下一篇:<a href='article.php?act=".$act."&id=".$nextRow['id']."'>{$nextRow['title']}</a> ";
  }
  else
  {
   $PreNext['next'] = "下一篇:没有了!";
    
  }
 }
/****************定义方法获取上下篇***************************/
if($arc['id'] !=""){
   include(dirname(__FILE__).'/templets/article.htm');
  }else{
   ShowMsg('非法请求,请勿修改参数!', '/');
   exit(); 
  }

注意:上下篇调用参考如下:
  <!--上下篇-->
   <div class="prenext">
    <ul>
      <li><?php echo $PreNext['pre']; ?></li>
      <li><?php echo $PreNext['next']; ?></li>
    </ul>
   </div>
  <!--上下篇-->
1 0
原创粉丝点击