主页 > 网站建设 > 建站知识 > 在dedecms搜索模板中调用自定义字段名的方法

在dedecms搜索模板中调用自定义字段名的方法

POST TIME:2017-12-15 22:50

在dedecms搜索模板中调用自定义字段名,默认dedecms搜索页面是没法使用[field:price/]来调用dede_addonshop里面的price字段的,

下面给大家分享下解决方法:

修改include/arc.searchview.class.php
第一处:
将大约320行地方的代码:
if($this->ChannelType < 0 || $this->ChannelTypeid< 0){
if($this->ChannelType=="0") $id=$this->ChannelTypeid;
else $id=$this->ChannelType;
$row =$this->dsql->GetOne("Select addtable From `cn_channeltype` Where id=$id");
$addtable = trim($row['addtable']);
$this->AddTable=$addtable;
}else{
$this->AddTable="cn_archives";
}
改为:
if($this->ChannelType=="0") $id=$this->ChannelTypeid;
else $id=$this->ChannelType;
$row =$this->dsql->GetOne("Select addtable From `cn_channeltype` Where id=$id");
$addtable = trim($row['addtable']);
if($this->ChannelType < 0 || $this->ChannelTypeid< 0){
$this->AddTable=$addtable;
$this->AddonTable='';
}else{
$this->AddTable="cn_archives";
$this->AddonTable=$addtable;
}
第二处:
将大约500行的地方的代码:
$query = "Select arc.*,act.typedir,act.typename,act.isdefault,act.defaultname,act.namerule,
act.namerule2,act.ispart,act.moresite,act.siteurl,act.sitepath
from `{$this->AddTable}` arc left join `cn_arctype` act on arc.typeid=act.id
where {$this->AddSql} $ordersql limit $limitstart,$row";
改为:
if (!empty($this->AddonTable)) {
$this->AddonTable="left join `{$this->AddonTable}` addon on addon.typeid=arc.typeid";
}else {
$this->AddonTable='';
}
$query = "Select arc.*,act.typedir,act.typename,act.isdefault,act.defaultname,act.namerule,
act.namerule2,act.ispart,act.moresite,act.siteurl,act.sitepath,addon.*
from `{$this->AddTable}` arc left join `cn_arctype` act on arc.typeid=act.id {$this->AddonTable}
where {$this->AddSql} $ordersql limit $limitstart,$row";
好了,可以在search.htm中使用[field:price/]了,只要你的模型有附加表,你就可以使用表里的任何字段
另外注意:如果附加表里有字段名和主表字段名一样的,使用[field:xxxx/]的结果是未定义的

 




收缩
  • 微信客服
  • 微信二维码
  • 电话咨询

  • 400-1100-266