PHPCMS 相关阅读调用当前栏目的解决办法

2012-11-10 浏览:959
PHPCMS 相关阅读调用当前栏目的解决办法
评论:(0)复制地址

PHPCMS 相关阅读官方的调用标签如下,但问题是调用之后不是当前栏目,而是全局。

{pc:content action="relation" relation="$relation" id="$id" catid="$catid" num="4" keywords="$rs[keywords]" order="updatetime dESC"}
              {if $data}
                <div class="Relevant">
                   <h2>相关案例</h2>
                   <ul class="clear">
                        {loop $data $r}
                            <li><a title="{$r['title']}" href="{$r[url]}" target="_blank">
                         <img src="{thumb($r[thumb],216,0)}" title="{$r[title]}"/>
                     </a></li>
                        {/loop}
                    </ul>
                </div>
              {/if}
 {/pc}

解决相关阅读调用当前栏目的办法很简单:

打开phpcms\modules\content\classes\content_tag.class.php,然后修改代码如下,注意红色部分:

public function relation($data) {
  $catid = intval($data['catid']);
  if(!$this->set_modelid($catid)) return false;
  $order = $data['order'];
  $sql = "`status`=99";
  $sql = "`catid`=$catid"; //加一句这个就正常了,没有做空判断 20121110
  $limit = $data['id'] ? $data['limit']+1 : $data['limit'];
  if($data['relation']) {
   $relations = explode('|',trim($data['relation'],'|'));
   $relations = array_diff($relations, array(null));
   $relations = implode(',',$relations);
   $sql = " `id` IN ($relations)";
   $key_array = $this->db->select($sql, '*', $limit, $order,'','id');
  } elseif($data['keywords']) {
   $keywords = str_replace('%', '',$data['keywords']);
   $keywords_arr = explode(' ',$keywords);
   $key_array = array();
   $number = 0;
   $i =1;
   foreach ($keywords_arr as $_k) {
    $sql2 = $sql." AND `keywords` LIKE '%$_k%'".(isset($data['id']) && intval($data['id']) ? " AND `id` != '".abs(intval($data['id']))."'" : '');
    $r = $this->db->select($sql2, '*', $limit, '','','id');
    $number += count($r);
    foreach ($r as $id=>$v) {
     if($i<= $data['limit'] && !in_array($id, $key_array)) $key_array[$id] = $v;
     $i++;
    }
    if($data['limit']<$number) break;
   }
  }
  if($data['id']) unset($key_array[$data['id']]);
  return $key_array;
 }

评论:(0)复制地址
发布:苗景云 | 分类:IT技术&设计 | Tags:PHPCMS

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。