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;
}
相关文章
PHPCMS 统计栏目下子栏目数量的代码2024-11-12
PHPCMS V9 上传图片或附件后后台退出需要重新登录的解决办法2021-06-19
PHPCMS 推荐位输出组图的方法2020-12-30
PHPCMS内容页自定义下拉菜单循环输出数值的方法2020-12-17
PHPCMS v9 search模块搜索栏目名称二次开发2020-02-20
PHPCMS删除文章后数据库中仍有删除文章中的关键词解决办法2019-11-13
PHPCMS中TAG模板、COMMENT模板等不能使用{SITEURL($SITEID)}函数2019-11-13
PHPCMS V9编辑器中新增上传mp4视频(上传视频并插入HTML5的video标签)的功能2019-10-30
PHPCMS一些漏洞修复及解决方案2019-07-10
PHPCMS的产品筛选功能(通用)2019-04-09