在用phpcms建设网站时,使用如下标签语句调用标题包含“最新”关键词的文章,但是会出现生效的是在全站文章中查询,但是实际我们需要在当前栏目下查询包含“最新”关键词的文章。
{php $where = " `title` LIKE '%最新%'" } {pc:content action="lists" catid="$v[catid]" where="$where" num="5" order="listorder DESC"} {loop $data $v} <li><em>{date('m/d',$v[inputtime])}</em><a href="{$v[url]}" target="_blank">{$v[title]}</a></li> {/loop} {/pc}
这时应该如何处理呢?经过查阅资料,可以通过修改/phpcms/modules/content/classes/content_tag.class.php文件,来解决这个问题。具体方法为,在content_tag.class.php文件中找到以下代码:
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; } }
如果你没有二次开发过phpcms,一般在63行左右。修改为以下代码:
if(isset($data['where'])) { $where = (isset($data['where'])&&(!empty($data['where'])))?' AND '.$data['where']:''; $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".$where." AND catid IN ($catids_str)".$thumb; } else { $sql = "status=99".$where." AND catid='$catid'".$thumb; } } 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; } }
完成以上修改步骤,就可以正常调用当前栏目下标题包含指定关键词的内容了,如果你也遇到了类似的问题就试试看吧。
如果内容有帮助,就点个赞吧!