phpcms v9关联文章排序陈旧问题的修改方法

之前一直没有注意过相关阅读的排序问题,今天偶尔看帖有网友说道,才发现,果真如此。调用出来的内容十分陈旧。于是尝试添加 order=id DESC 参数进行排序,调用顺序依然毫无变化。打开 phpcms/modules/content/classes/content_tag.class.php 内容模型标签类一看,发现该标签仅在内容存在人为设置的相关阅读时,才依照order参数进行排序。而当内容不存在人为设置的相关阅读时,则按照关键字进 行查询,但此时并没有按照order参数进行排序。而是不进行排序。这也就是为什么文章调用的相关阅读总是那么陈旧的原因了。
修正该问题的方法如下:
修改 phpcms/modules/content/classes/content_tag.class.php 内容模型标签类文件,将 content_tag 类中 relation 方法修改为:

        /**
* 相关文章标签
* @param $data
*/
public function relation($data) {
$catid = intval($data['catid']);
if(!$this->set_modelid($catid)) return false;
$order = $data['order'];
$sql = "`status`=99";
$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,'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;
}

其实只是将 $r = $this->db->select($sql2,'id'); 替换为了 $r = $this->db->select($sql2,'id'); 让order参数传入查询方法。
在模板当中,使用如下标签,加上order参数即可实现排序了。

{pc:content action="relation" relation="$relation" id="$id" catid="$catid" num="5" keywords="$rs[keywords]" order="id DESC"}
{loop $data $r}
{/loop}
{/pc}

如果有洁癖的朋友,担心直接修改PC会影响未来升级,可以将其单独提取出来。放到模板中当作函数使用。代码如下:

<?php
/**
* 内容模型 - 相关文章标签(修正排序异常问题)
* @param $data
*/
function mk1_content_tag_relation($data) {
$db = pc_base::load_model('content_model');
$catid = intval($data['catid']);
$siteids = getcache('category_content','commons');
if(!$siteids[$catid]) return false;
$siteid = $siteids[$catid];
$category = getcache('category_content_'.$siteid,'commons');
if(empty($category)) return false;
if($category[$catid]['type']!=0) return false;
$db->set_model($category[$catid]['modelid']);
$order = $data['order'];
$sql = "`status`=99";
$limit = $data['id'] ? $data['limit']+1 : $data['limit'];
if($data['relation']) {
$relations = explode('|','|'));
$relations = array_diff($relations,array(null));
$relations = implode(',$relations);
$sql = " `id` IN ($relations)";
$key_array = $db->select($sql,'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 = $db->select($sql2,'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;
}
?>

在模板中,使用如下PHP代码获取即可。


{php $data = mk1_content_tag_relation(array('relation'=>$relation,'id'=>$id,'catid'=>$catid,'keywords'=>$rs['keywords'],'order'=>'id DESC','limit'=>'4')); }
{loop $data $r}
{/loop}

其实只是一个小问题,PC在未来应该会进行修正的,以上方法提供给那些心急的站长朋友们。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


本教程操作系统:Windows10系统、phpcms 9版本、Dell G3电脑。PHPcms排序的作用是什么?
PHPcms访问特点:单一入口模式。无论访问任何一个模块或者功能,只有一个统一的入口。参数名称描述位置m模型/模块名称phpcms/moudles中的模块目录名称c控股器名称phpcms/moudles/模块/*.php文件名称a事件名称phpcms/moudles/模块/*.php中的方法名称例子:
例如:{pc:contentaction="position"posid="2"order="listorderDESC"num="4"}后台-推荐位管理(左边栏最下方),里面可以自定义ID下面为默认的:在V9的后台添加文章页面中的源代码中得知推荐位有5种类型:1首页焦点图推荐2首页头条推荐9网站顶部推荐10栏目首页推荐12首页图片推荐
首先,上图之中的红色框框是没有的,我们想要给他加上,当然是要改HTML页面啦,废话,我们跟ECSHOP一样由PHP路径找模板;看看路由原理:   首先,上图之中的红色框框是没有的,我们想要给他加上,当然是要改HTML页面啦,废话,我们跟ECSHOP一样由PHP路径找模板;看看路由原理: 再看看这个板块的
头部<metaname="keywords"content="{$SEO['keyword']}"/><metaname="description"content="{$SEO['description']}"/><title>{ifisset($SEO['title'])&&!empty($SE
做网站时用的到的简单的栏目导航()phpcms多个栏目catidin(9,10,11)可以修改id排序orderbylistorderASC/DESC{if}...{/if}为判断点击为栏目下面是一种例子html:<divstyle="width:1000px;height:45px;"class="dh"><ul><liclass="navb"><ahref=&quot
首先在phpcms/libs/functions/extention.func.php里面写入判断手机访问的自定义函数?123456789101112131415161718192021222324252627282930313233343536373839<?php/** *extention.func.php用户自定义函数库 * *@co
phpcmsv9和dedecms自带的编辑器都是使用的ckeditor,在默认情况下使用ckeditor编辑内容时,按下回车键后在源代码显示的是<br>而非<p>标签,对于习惯于换行为p标签的我来说极为不便。phpcmsv9编辑器ckeditor设置回车换行<br>为段落<p>标签修改方法:在\statics\js\ckeditor\config.js
原文链接:http://www.cnblogs.com/Republic/p/4783705.htmlPHPCMS后台框架实现思路【原创】时间 2014-11-2710:12:19极客头条原文 http://blogs.zmit.cn/3589.html1.打开后台入口文件admin.phpheader('location:index.php?m=admin');跳转到in
加载系统类方法load_sys_class($classname,$path=‘’",$initialize=1)系统类文件所在的文件路径:/phpcms/libs/classes/文件夹下参数说明:@paramstring$classname类名@paramstring$path扩展地址@paramintgerinitialize是否初始化如要调用系统Form类的生
**1.F:…\caches\configs\route.php文件中配置路径2.F:…\caches\configs\url_route.php配置第二个站点的301跳转,根据站点id加载不同的路由.3.删除入口的加载文件4创建…phpcms\modules\content\classes\template_style.class.php由$_SERVER[‘HTTP_HOST’]
如下图所示功能: 首先,用下面这些代码替换掉phpcms/libs/functions/extention.func.php的内容<?php/***extention.func.php用户自定义函数库**@copyright(C)2005-2010PHPCMS*@licensehttp://www.phpcms.cn/license/*@lastmodify
头部<metaname="keywords"content="{$SEO['keyword']}"/><metaname="description"content="{$SEO['description']}"/><title>{ifisset($SEO['title'])&&!empty($S
今天修改一位客户的phpcms网站,他要求添加https,这对ytkah来说是轻车熟路了,但是后台稍微有点问题,点击分页出现错误,将鼠标移到下一页显示的链接是https://www.abc.com/www.abc.com/index.php?m=content&c=content&a=init&menuid=822&catid=37&pc_hash=GsxXx8&page=2,很明显是多了一
location/{if(!-f$request_filename){rewrite(.*)/index.php;}rewrite^/caipu-([0-9]+)-([0-9]+)-([0-9]+).html/index.php?m=content&c=index&a=show&catid=$1&id=$2&page=$3last;rewrite^/content-([0-9]+)-([0-9]+)-([0-9]+).html/ind
PHP打印方法: {php&#160;print_r(变量);} {php&#160;print_r(变量);} &lt;?php&#160;print_r(变量);?&gt; 1. &lt;div
调用一级栏目名称跟二级栏目名称:
phpcms如何修改图片水印呢1、首先准备一张水印图片,命名为mark png(名字随意),放到网站根目录statics images water 文件夹下2、进入网站后台,单击 设置->站点管理,修改站点,如下图所示,进行相关参数设置即可
就目前phpcms2008下PHPCMS绑定二级域名地址不正确问题分析,在生成栏目的url时有bug,如下所示:比如当栏目wfuyu 绑定二级域名为http: wfuyu phpcms com存在路径为 parentdir=& 39;ja ywja ydzd