帝国CMS灵动标签循环子栏目数据

帝国CMS循环子栏目数据调用标签,调用的子栏目数据只能调用一种信息,比如只能调用一组最新信息,如何同时调用一组最新信息及点击排行信息呢?

PHPCMS调用默认表最新文章有一下两种方法:

帝国CMS灵动标签循环子栏目数据,同时调用点击排行及最新信息,当然也可以是其它两种信息调用,如下图为例:

?php$bclassid=$GLOBALS[navclassid]; //取得本栏目id//取得本栏目下的子栏目?[e:loop={select classid, classname, classpath from `[!db.pre!]enewsclass` where bclassid='$bclassid' order by `classid` desc ,7,24,0}][ecmsinfo] $bqr[classid] ,14,30,1,0,29,0[/ecmsinfo] [ecmsinfo] $bqr[classid] ,14,30,1,0,27,0[/ecmsinfo] [/e:loop] 
  1. get标签形式调用

  2. 修改标签代码实现最新文章调用

如上图所示,左边调用点击排行,右边调用最新信息。代码如下:

下面我们看看具体是实现方法:

divclass=intabbkid=shtree1h3/h3spanclass=moreahref=[!---news.url--]list-1-0.htmltarget=_blank更多/a/spandivid=tab-hdclass=deep-hd[showclasstemp]1,13,0,0[/showclasstemp]/divdivid=tab-bdclass=deep-bd[e:loop={selectclassid,classname,classpathfrom`[!db.pre!]enewsclass`wherebclassid=1orderbymyorderasc,7,24,0}]divclass=dcondivclass=topldivclass=top10b销售排行/bTOP10/div?php//这里是取得该分类下的有图片的最新数据$newbook1=$empire-query(selecttitle,titlepic,titleurl,keyboard,newstime,groupid,tprice,price,classid,newspath,filename,idfromphome_ecms_shopwhereclassid=.$bqr[classid].orderbyonclickdesclimit6);while($r=$empire-fetch($newbook1)){$commbookurl=sys_ReturnBqTitleLink($commbook1);?dldtahref=?=sys_ReturnBqTitleLink($r)?target=_blankimgsrc=?=$r[titlepic]?width=60height=60//a/dtddahref=?=sys_ReturnBqTitleLink($r)?target=_blank?=$r[title]?/a/ddddspanclass=price市价:?=$r[tprice]?/span/ddddspanclass=priceb售价:?=$r[price]?/span/dd/dl?php}?divclass=goahref=[!---news.url--]list-1-0.htmltarget=_blank进入进口食品/a/div/divdivclass=goodsbkulclass=goods_list?php$newbook=$empire-query(selecttitle,titlepic,titleurl,keyboard,newstime,groupid,tprice,price,classid,newspath,filename,idfromphome_ecms_shopwhereclassid=.$bqr[classid].orderbynewstimedesclimit8);while($r=$empire-fetch($newbook)){?lidivclass=pic_wrapahref=?=sys_ReturnBqTitleLink($r)?target=_blankimgalt=?=$r[title]?src=?=$r[titlepic]?/a/divdivclass=price_wrappclass=pricespan¥/span?=$r[price]?/p/divdivclass=title_wrapatitle=?=$r[title]?href=?=sys_ReturnBqTitleLink($r)?target=_blank?=$r[title]?/a/div/li?php}?/ul/div/div[/e:loop]/div

第一种方法 用GET标签调用

这种方法不用修改PHPCMS的核心代码,就可以达到模型表的最新数据调用,具体代码片段如下:

{pc:get sql="SELECT * from v9_news where status=99 and catid in(21,22,23,24,25) order by id DESC" start=="7" num="7" return="data"} {loop $data $r} <li><a href="{$r[url]}" title="{$r[title]}" target="_blank">{str_cut($r['title'],40)}({date('m-d',$r[inputtime])})</a></li> {/loop} {/pc}

第二种方法 修改标签代码

PHPCMS的标签默认只能调用单个主栏目下面的子栏目的文章,如果不填写栏目则无法调用数据,填写多个栏目ID只调取首个栏目ID的文章,为什么这么说呢?看看代码就知道原因所在了。

 /**   * 列表页标签   * @param $data   */  public function lists($data) {   $catid = intval($data['catid']);   if(!$this->set_modelid($catid)) return false;   if(isset($data['where'])) {    $sql = $data['where'];   } else {    $thumb = intval($data['thumb']) ? " AND thumb != ''" : '';    if($this->category[$catid]['child']) {     $catids_str = $this->category[$catid]['arrchildid'];     $pos = strpos($catids_str,',')+1;     $catids_str = substr($catids_str, $pos);     $sql = "status=99 AND catid IN ($catids_str)".$thumb;    } else {     $sql = "status=99 AND catid='$catid'".$thumb;    }   }   $order = $data['order'];    $return = $this->db->select($sql, '*', $data['limit'], $order, '', 'id');          //调用副表的数据   if (isset($data['moreinfo']) && intval($data['moreinfo']) == 1) {    $ids = array();    foreach ($return as $v) {     if (isset($v['id']) && !empty($v['id'])) {      $ids[] = $v['id'];     } else {      continue;     }    }    if (!empty($ids)) {     $this->db->table_name = $this->db->table_name.'_data';     $ids = implode('','', $ids);     $r = $this->db->select("`id` IN ('$ids')", '*', '', '', '', 'id');     if (!empty($r)) {      foreach ($r as $k=>$v) {       if (isset($return[$k])) $return[$k] = array_merge($v, $return[$k]);      }     }    }   }   return $return;  }

修改为添加所以栏目ID来查询全表数据。这样和GET方法几乎没什么区别,只是标签形式不同而已

 /**   * 列表页标签   * @param $data   */  public function lists($data) {   $catid = $data['catid'];   $cid = intval( $catid );   if(!$this->set_modelid($cid)) return false;   if(isset($data['where'])) {    $sql = $data['where'];   } else {    $thumb = intval($data['thumb']) ? " AND thumb != ''" : '';    if($cat_array=explode(',',$catid) ){       $catids_str = $catid;       foreach($cat_array as $k => $v){        if($this->category[$v]['child']) {         $catids_str .= ','.$this->category[$v]['arrchildid'];        }       }       $sql = "status=99 AND catid IN ($catids_str)".$thumb;      }else {     $sql = "status=99 AND catid='$catid'".$thumb;    }   }   $order = $data['order'];    $return = $this->db->select($sql, '*', $data['limit'], $order, '', 'id');          //调用副表的数据   if (isset($data['moreinfo']) && intval($data['moreinfo']) == 1) {    $ids = array();    foreach ($return as $v) {     if (isset($v['id']) && !empty($v['id'])) {      $ids[] = $v['id'];     } else {      continue;     }    }    if (!empty($ids)) {     $this->db->table_name = $this->db->table_name.'_data';     $ids = implode('','', $ids);     $r = $this->db->select("`id` IN ('$ids')", '*', '', '', '', 'id');     if (!empty($r)) {      foreach ($r as $k=>$v) {       if (isset($return[$k])) $return[$k] = array_merge($v, $return[$k]);      }     }    }   }   return $return;  }

标签调用形式,默认第一个栏目ID为模型表:

{pc:content action="lists" catid="1,2,3,4,5" order="listorder DESC,inputtime DESC,id DESC" moreinfo="1"  start="7" num="7"}  {loop $data $k $v}    <li><a href="{$v[url]}" title="{$v[title]}" target="_blank"{title_style($v[style])}>{str_cut($v[title], 100)}</a></li>  {/loop} {/pc}

版权声明:本文为博主原创文章,未经博主允许不得转载。


发表评论

电子邮件地址不会被公开。 必填项已用*标注