王蕾蕾 發表於 2024-4-10 00:00:00

详解dedecms搜索页面单独调用搜索结果条数的实现方法

<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        DEDE的搜索结果数量都集成在了列表分页标签里,并没有使用单独的函数来提供这个结果数量,因此对有单独调用搜索结果数量的用户来说,就有使用问题,这里提供二次开发的方法。</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        非常简单只要修改几个地方就行了:</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        <strong>第一步,打开/include/arc.searchview.class.php文件,查找代码(大概在第525行):</strong></p>
<div class="jb51code" style='margin: 0px; padding: 0px; outline: none; line-height: 25.2px; font-size: 14px; width: 660px; overflow: hidden; clear: both; font-family: tahoma, arial, "Microsoft YaHei";'>
        <pre class="brush:php;toolbar:false;">
else if($tagname=="pagelist")
{
      $list_len = trim($ctag-&gt;GetAtt("listsize"));
      if($list_len=="")
      {
                $list_len = 3;
      }
      $this-&gt;dtp-&gt;Assign($tagid,$this-&gt;GetPageListDM($list_len));
}
</pre>
</div>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        在下面添加代码:</p>
<div class="jb51code" style='margin: 0px; padding: 0px; outline: none; line-height: 25.2px; font-size: 14px; width: 660px; overflow: hidden; clear: both; font-family: tahoma, arial, "Microsoft YaHei";'>
        <pre class="brush:php;toolbar:false;">
else if($tagname=="itemcount")
{
      $list_len = trim($ctag-&gt;GetAtt("listsize"));
      if($list_len=="")
      {
                $list_len = 3;
      }
      $this-&gt;dtp-&gt;Assign($tagid,$this-&gt;GetItemsCountDM($list_len));
}
</pre>
</div>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        <strong>第二步,查找代码(大概在第925行):</strong></p>
<div class="jb51code" style='margin: 0px; padding: 0px; outline: none; line-height: 25.2px; font-size: 14px; width: 660px; overflow: hidden; clear: both; font-family: tahoma, arial, "Microsoft YaHei";'>
        <pre class="brush:php;toolbar:false;">
/**   * 获得当前的页面文件的url   *   * @access public   * @return string   */</pre>
</div>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        在其上面添加下面的这段代码:</p>
<div class="jb51code" style='margin: 0px; padding: 0px; outline: none; line-height: 25.2px; font-size: 14px; width: 660px; overflow: hidden; clear: both; font-family: tahoma, arial, "Microsoft YaHei";'>
        <pre class="brush:php;toolbar:false;">
function GetItemsCountDM($list_len)
{
      global $oldkeyword;
      $pagenow = ($this-&gt;PageNo-1) * 10 + 1;
      $pagenows = $this-&gt;PageNo*10; //当结果超过限制时,重设结果页数
      if($this-&gt;TotalResult &gt; $this-&gt;SearchMaxRc)
      {
                $totalpage = ceil($this-&gt;SearchMaxRc/$this-&gt;PageSize);
      }
      $plist .= $this-&gt;TotalResult;
      return $plist;
}
</pre>
</div>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        <strong>第三步,在搜索结果页模板里要显示结果条数的地方通过如下标签调用:</strong></p>
<div class="jb51code" style='margin: 0px; padding: 0px; outline: none; line-height: 25.2px; font-size: 14px; width: 660px; overflow: hidden; clear: both; font-family: tahoma, arial, "Microsoft YaHei";'>
        <pre class="brush:xml;toolbar:false;">
{dede:itemcount listsize='4'/}</pre>
</div>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        这样就可以实现搜索结果页的搜索结果数量的单独调用了。</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。</p>
頁: [1]
查看完整版本: 详解dedecms搜索页面单独调用搜索结果条数的实现方法