PageAdmin网站内容管理系统(CMS)交流论坛

注册

 

QQ登录

只需一步,快速开始

发新话题 回复该主题

如何实现分类搜索 [复制链接]

1#
现在的搜索是在搜索整个news表的全部新闻,想实现按照新闻中心的二级栏目columnid分类搜索,
分享 转发
TOP
2#

给搜索模板加多一个栏目id参数就是了
TOP
3#

回复 2楼搜企网络的帖子

怎么加呀,求详解
TOP
4#

http://www.pageadmin.net/help/37.cshtml  
在实例5的基础上帮你改一下,你自己完善一下。
  1. <ul>
  2.     @{
  3.        var keyword=StringHelper.Format<string>(Request.QueryString["keyword"]); //关键词参数
  4.        var columnId=StringHelper.Format<int>(Request.QueryString["columnId"]);  //栏目id参数
  5.         PageInfo pageInfo=new PageInfo()
  6.         {
  7.             PageSize=10,
  8.             CurrentPage=(int)ViewBag.CurrentPage
  9.         };
  10.         foreach (var item in Html.InfoDataList(new {Table="news", HasThumbnail=1, OrderBy="thedate desc" }, "columnId=@columnId and title like @keyword", new {columnId=columnId, keyword="%"+keyword+"%" }, pageInfo))
  11.         {
  12.             string url=Html.InfoDataUrl((int)item.ColumnId, (int)item.Id);
  13.             <li>
  14.              <span><a href="@url" target="_blank">@item.Title</a></span>
  15.             </li>
  16.         }
  17.     }
  18. </ul>
复制代码
keyword和columnId直接从url地址参数中传递
最后编辑搜企网络 最后编辑于 2021-12-23 15:57:14
TOP
5#

回复 4楼搜企网络的帖子
  1. @{
  2.     int columnId = Html.CurrentColumnId();
  3.     string kw = StringHelper.Format<string>(HttpContext.Current.Request.QueryString["kw"]);
  4.     string[] pagePathArr = Html.PagePath().Split('/');
  5.     int currentPage = StringHelper.Format<int>(Html.CustomViewParameter("page"));
  6.     if (currentPage <= 0)
  7.     {
  8.         currentPage = 1;
  9.     }
  10.     PageInfo pageInfo = new PageInfo()
  11.     {
  12.         PageSize = 10,//每页显示10条数据
  13.         CurrentPage = currentPage //当前页码,系统预设
  14.     };
  15.     var dataList = Html.InfoDataList(new { Table = "news" }, "title like @kw", new { kw = "%" + kw + "%" }, pageInfo);
  16.     ViewBag.Path = "/news/Search/"; //PagebreakPartial分页文件用到
  17. }
  18. <div class="container padding-bottom-60">
  19.     <ul class="breadcrumb">
  20.         <li><a href="@Html.SiteUrl()"><span class="fa fa-home"> 首页</span></a></li>
  21.         <li><a href="">文章搜索</a></li>
  22.     </ul>
  23.     <ul class="news-list padding-top-10">
  24.         @{int num = 0;
  25.             foreach (var item in dataList)
  26.             {
  27.                 num++;
  28.                 string url = Html.InfoDataUrl((int)item.ColumnId, (int)item.Id);
  29.                 string date = item.Thedate.ToString("yyyy-MM-dd");
  30.                 <li class="item">
  31.                     <span class="title">
  32.                         <a href="@url" target="_blank" title="@item.Title">@item.Title</a>
  33.                     </span>
  34.                     <span class="date">@date</span>
  35.                 </li>
  36.             }
  37.             if (num == 0)
  38.             {
  39.                 <li class="line-height-2 padding-bottom-20 padding-top-20">
  40.                     暂时没有找到匹配的记录,请更换一个关键词重新搜索!
  41.                 </li>
  42.             }
  43.         }
  44.     </ul>
  45.      @Html.Partial("PagebreakPartial", pageInfo)
  46. </div>

  47. <script>
  48.     $("#input-search").val("@kw");
  49.    // $searchBtn.trigger("click");//触发搜索按钮,显示搜索框
  50. </script>
复制代码
可不可以在这改一下 拜托了
TOP
6#

int currentPage = StringHelper.Format<int>(Html.CustomViewParameter("page"))的下面加一行
var columnId=StringHelper.Format<int>(Request.QueryString["columnId"]);  //栏目id参数

Html.InfoDataList(new { Table = "news" }, "title like @kw", new { kw = "%" + kw + "%" }, pageInfo);
改为
Html.InfoDataList(new {Table="news"}, "columnId=@columnId and title like @kw", new {columnId=columnId, kw="%"+kw+"%" , pageInfo},
TOP
7#

回复 6楼搜企网络的帖子

谢谢谢谢,在请问一下,首页要怎么改呀
  1. @{
  2.     int columnId = Html.CurrentColumnId();
  3.     var siteData = Html.SiteData();
  4.     string[] hostKeywords = new string[] { "通知","规定", "办法", "请假单","推荐","社发", "党发" };
  5. }

  6. <div class="header clearfix">
  7.     <div class="container">
  8.         <div class="row">
  9.             <div class="col-md-3 float-lg-left">
  10.                 <a class="logo" href="@Html.SiteUrl()">
  11.                     <img src="@siteData.Logo" />
  12.                 </a>
  13.             </div>
  14.             <div class="col-md-9">
  15.                 <div class="nav text-right col-md-right" id="navMenu">
  16.                     @Html.SiteColumnsHtml()
  17.                 </div>
  18.             </div>
  19.             <div class="mask-bg" id="maskBg"></div>
  20.             <div class="right-icon-box">
  21.                 <i class="fa fa-search" aria-hidden="true" id="searchBtn"></i>
  22.                 <i class="fa fa-remove hidden" id="removeSearch"></i>
  23.                 <i class="fa fa-bars" id="navToggle"></i>
  24.             </div>
  25.         </div>
  26.     </div>
  27. </div>

  28. <!-- 搜索隐藏模块-->
  29. <div class="search-show">

  30.     <div class="box container">

  31.         <div class="title">
  32.             <input type="text" class="s-input" id="input-search" placeholder="请输入你要查找的产品" />
  33.             <i class="fa fa-search s-btn"></i>
  34.         </div>
  35.         <div class="hot-word">
  36.             <div class="text">热搜关键词</div>
  37.             <ul>
  38.                 @foreach (var keyword in hostKeywords)
  39.                 {
  40.                     <li><a href="/news/Search/?kw=@(Server.UrlEncode(keyword))">@keyword</a></li>
  41.                 }
  42.             </ul>
  43.         </div>
  44.     </div>

  45. </div>
  46. <div class="search-bg" id="SearchMask"></div>


  47. <script type="text/javascript">
  48.     var $navToggle = $("#navToggle");//手机端菜单图标
  49.     var $maskBg = $("#maskBg");//遮挡层
  50.     var $navMenu = $("#navMenu");
  51.     $navToggle.on("click", function () {
  52.         $maskBg.addClass("active");
  53.         $navMenu.addClass("active");
  54.     });
  55.     $maskBg.on("click", function () {
  56.         $maskBg.removeClass("active");
  57.         $navMenu.removeClass("active");
  58.     });
  59.     $navMenu.children("ul").find("li").InitNav(@Html.CurrentColumnId(),@Html.TopColumnId());//初始化响应式菜单

  60.     //搜索展示
  61.     var $searchBtn = $('#searchBtn');
  62.     var $removeSearch = $('#removeSearch');
  63.     var $searchshow = $('.search-show');
  64.     var $searchbg = $('.search-bg');
  65.     $searchBtn.on("click", function () {
  66.         $(this).toggleClass("hidden");
  67.         $removeSearch.toggleClass("hidden");
  68.         $searchshow.slideToggle();
  69.         //$searchbg.toggle();
  70.     })
  71.     $removeSearch.on("click", function () {
  72.         $(this).toggleClass("hidden");
  73.         $searchBtn.toggleClass("hidden");
  74.          $searchshow.slideUp();
  75.          //$searchbg.hide();
  76.      })

  77.     var keyword = "";
  78.     var $s_input = $(".s-input");
  79.     $(".s-btn").on("click", function () {
  80.         keyword = $s_input.val();
  81.         if (keyword != "") {
  82.             location.href = "/news/Search/?kw=" + keyword;
  83.         }
  84.     });
  85.     $(".s-input").on("keydown", function (event) {
  86.     var key = event.which;
  87.     if (key == 13){
  88.         keyword = $s_input.val();
  89.             if (keyword != "") {
  90.                 location.href = "/news/Search/?kw=" + keyword;
  91.             }
  92.          }
  93.     });

  94.   
  95. </script>
复制代码
最后编辑李木木 最后编辑于 2021-12-23 16:36:27
TOP
8#

后台获取栏目id,组合成一个下拉选择菜单,还有js脚本也要加一个栏目id的参数传递,改动太多了,剩下你自己研究一下
TOP
9#

回复 8楼搜企网络的帖子

下单菜单我会,但是参数传递怎么加呀
TOP
发新话题 回复该主题