动易CMS-搜索结果页显示自定义字段

最终的页面:

 

 

步骤:

1.搜索标签代码

<input id="keyword" type="text" class="text" onfocus= "this.style.color='#000';
          if(this.value=='品牌/型号/套餐/配件')this.value=''" onblur="if(this.value==''){this.value='品牌/型号/套餐/配件';this.style.color='#999'}" maxlength="100" value="品牌/型号/套餐/配件" name="Keyword" />
<div class="search_word"> <input id="Submit" type="submit" value="搜索" name="Submit" class="sub" onclick="OnSearchCheckAndSubmit();" /></div>
<script type="text/javascript">
var searchBox=document.getElementById("keyword");
searchBox.onkeydown=entersearch;
 
function OnSearchCheckAndSubmit(){
      var keyword = searchBox.value;
      if (keyword == '' || keyword == null ||keyword == '品牌/型号/套餐/配件') {
          alert("您没有输入任何内容!");
          return;
      }
      else {
          window.location = "{PE.SiteConfig.applicationpath/}search.aspx?searchtype=0&Keyword=" + escape(keyword);
      }
  }
function entersearch(event){
        var event = event|| window.event;
        if (event.keyCode == 13)
        {
            OnSearchCheckAndSubmit();
        }else{
            return;  
        }
    }
</script>

 

   

2.添加自定义字段(前面文章有介绍到);

3.选择全站搜索结果页模板(“系统设置”→“模板标签管理”→“动态页模板配置”)

    

 4.修改“全站搜索按标题 ”标签的查询语句(红色的为添加的字段所在的表中)

<xsl:template match="/">
  {PE.Label id="全站搜索按标题_普通式" queryCond="SELECT TOP @pagesize
  *
  FROM
  PE_CommonModel CM INNER JOIN PE_U_Photo PP ON(CM.GeneralID=PP.ID)
  WHERE
  CM.GeneralID NOT IN (SELECT TOP @startrow ICM.GeneralID FROM PE_CommonModel ICM WHERE ICM.Status = 99 AND ICM.Title LIKE '%<xsl:value-of select="/NewDataSet/Table/Title"/>%' ORDER BY ICM.UpdateTime DESC) AND
  CM.Status = 99 AND CM.SigninType!=2 AND
  CM.Title LIKE '%<xsl:value-of select="/NewDataSet/Table/Title"/>%'
  ORDER BY
  CM.UpdateTime DESC" queryCount="SELECT COUNT (ICM.GeneralID) FROM PE_CommonModel ICM WHERE ICM.Status = 99 AND ICM.Title LIKE '%<xsl:value-of select="/NewDataSet/Table/Title"/>%'" titleLength="<xsl:value-of select="$titleLength"/>" page="true" pagesize="<xsl:value-of select="$outputQty"/>" urlpage="true" /}
 </xsl:template>

 5.在“全站搜索按标题_普通式”中添加所要显示的内容(红色的部分)

<?xml version="1.0" encoding="utf-8"?>
<root>
  <LabelType>样式类</LabelType>
  <LabelIntro>
  </LabelIntro>
  <OutType>sin</OutType>
  <LabelDataType>sql_sysquery</LabelDataType>
  <EnabelAjax>False</EnabelAjax>
  <IsXsltSql>false</IsXsltSql>
  <IsXsltCountSql>false</IsXsltCountSql>
  <LabelSqlString>@queryCond </LabelSqlString>
  <attributes>
    <name>queryCount</name>
    <datatype>supersql</datatype>
    <default>
    </default>
    <intro>统计条件</intro>
  </attributes>
  <attributes>
    <name>queryCond</name>
    <datatype>supersql</datatype>
    <default>SELECT TOP 10 * FROM PE_CommonModel</default>
    <intro>查询条件</intro>
  </attributes>
  <attributes>
    <name>titleLength</name>
    <datatype>supersql</datatype>
    <default>60</default>
    <intro>标题长度</intro>
  </attributes>
  <attributes>
    <name>imageClass</name>
    <datatype>string</datatype>
    <default>pe_u_thumb</default>
    <intro>图片区块选择器名</intro>
  </attributes>
  <attributes>
    <name>titleClass</name>
    <datatype>string</datatype>
    <default>pe_u_thumb_title</default>
    <intro>标题简介区择器名</intro>
  </attributes>
  <attributes>
    <name>xsjgClass</name>
    <datatype>double</datatype>
    <default>pe_u_thumb_xsjg</default>
    <intro>显示价格区择器名</intro>
  </attributes>
  <attributes>
    <name>imageWidth</name>
    <datatype>int</datatype>
    <default>160</default>
    <intro>图片宽度</intro>
  </attributes>
  <attributes>
    <name>imageHeight</name>
    <datatype>int</datatype>
    <default>120</default>
    <intro>图片高度</intro>
  </attributes>
  <attributes>
    <name>optionalExtend</name>
    <datatype>string</datatype>
    <default />
    <intro>可选扩展参数</intro>
  </attributes>
  <UsePage>True</UsePage>
  <LabelDataType>sql_sysquery</LabelDataType>
  <IsXsltSql>false</IsXsltSql>
  <IsXsltCountSql>false</IsXsltCountSql>
  <LabelSqlString>@queryCond </LabelSqlString>
  <LabelSqlCount>@queryCount</LabelSqlCount>
  <Version officialVersion="" modifiedVersions="3607" compatibleVersion="" />
  <LabelTemplate><![CDATA[<?xml version="1.0" encoding="utf-8"?>
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:pe="labelproc" exclude-result-prefixes="pe">
<xsl:output method="html"  version="1.0" encoding="utf-8" indent="yes"/>
<xsl:param name="contentLength" />
<xsl:param name="imageClass" />
<xsl:param name="titleClass" />
<xsl:param name="xsjgClass" />
<xsl:param name="imageWidth" />
<xsl:param name="imageHeight" />
<xsl:param name="queryCount" />
<xsl:param name="queryCond" />
<xsl:param name="optionalExtend" />
<xsl:param name="titleLength" />
<xsl:template match="NewDataSet">
<xsl:choose>
<xsl:when test="count(Table)=0">
<li style="color:red">没有相关搜索结果!</li>
</xsl:when>
<xsl:otherwise>
<xsl:for-each select="Table">
<li>
 
<div class="{$imageClass}"> <a>
<xsl:attribute name="href"> <xsl:value-of select="pe:GetInfoPath(NodeID,GeneralID,InputTime,PinyinTitle,HtmlPageName)" /> </xsl:attribute>
<xsl:attribute name="target">
<xsl:choose>
<xsl:when test="pe:GetNodeFieldName(NodeID, 'ItemOpenType') = 0">
_self
</xsl:when>
<xsl:otherwise>
_blank
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:element name="img">
<xsl:attribute name="src">
<xsl:choose>
<xsl:when test="DefaultPicUrl != ''">
<xsl:value-of select="pe:ConvertAbsolutePath(DefaultPicUrl)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="pe:UpLoadDir()"/>nopic.gif
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:attribute name="alt"> <xsl:value-of select="Title" /> </xsl:attribute>
<xsl:if test="$imageWidth &gt; 0">
<xsl:attribute name="width"> <xsl:value-of select="$imageWidth" /> </xsl:attribute>
</xsl:if>
<xsl:if test="$imageHeight &gt; 0">
<xsl:attribute name="height"> <xsl:value-of select="$imageHeight" /> </xsl:attribute>
</xsl:if>
<xsl:attribute name="border">0</xsl:attribute>
</xsl:element>
</a> 
</div>
 
<span>
<xsl:attribute name="href">
<xsl:value-of select="pe:GetInfoPath(NodeID,GeneralID,InputTime,PinyinTitle,HtmlPageName)"/>
</xsl:attribute>
<xsl:attribute name="target">_blank</xsl:attribute>
<xsl:attribute name="title">标题:<xsl:value-of select="Title"/>
</xsl:attribute>
<xsl:value-of select="pe:CutText(Title,$titleLength,'…')" />
</span>
 
<p>
<xsl:attribute name="href">
    <xsl:value-of select="/NewDataSet/Table/xsjg"/>
</xsl:attribute>
<xsl:attribute name="target">_blank</xsl:attribute>
<xsl:attribute name="xsjg">价格:<xsl:value-of select="xsjg"/>
</xsl:attribute>¥
<xsl:value-of select="pe:CutText(xsjg,$titleLength,'…')" />
</p> 
                   
</li>
 
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:transform>]]></LabelTemplate>
</root>

 

 

 

 

posted @ 2013-08-14 16:12  木子的紫微星  阅读(833)  评论(1编辑  收藏  举报