网络上的织梦搜索伪静态好代码教程基本都有,我就不说了。包括使用插件的也有,而且普遍是以下这种方式
伪静态前
www.xxx.com/plus/search.php?q=关键词
伪静态后
www.xxx.com/search/关键词.html
那问题就来了,我如果是要传参或者搜索展示指定的栏目内容咋办。就我经常使用get传参的话,就只能使用动态了。
但我又看着/plus/search.php?typeid=栏目id&q=关键词&PageNo=分页页数 有点别扭,于是想改成 www.xxx.com/search/?typeid=栏目id&q=关键词&PageNo=分页页数
经过一番折腾,还是勉强搞了出来。写个伪静态规则(写得不好,就是为了方便):
# nginx伪静态 if ($request_uri ~* "^/search/\?typeid=([0-9]+)$"){ set $myarg1 $1; rewrite .*/plus/search.php?typeid=$myarg1 last; } if ($request_uri ~* "^/search/\?typeid=([0-9]+)&q=(.*)$"){ set $myarg1 $1; set $myarg2 $2; rewrite .*/plus/search.php?typeid=$myarg1&q=$myarg2 last; } if ($request_uri ~* "^/search/\?typeid=([0-9]+)&q=(.*)$"){ set $myarg1 $1; set $myarg2 $2; set $myarg3 $3; rewrite .*/plus/search.php?typeid=$myarg1&q=$myarg2&PageNo=$myarg3 last; }
现在 www.xxx.com/search/?typeid=栏目id&q=关键词&PageNo=分页页数 可以正常访问了。
但是现在分页还不是我想要的,开始改/include/arc.searchview.class.php 从上一页下一页开始:
//获得上一页和下一页的链接 if($this->PageNo != 1) { $prepage.=$GLOBALS['rewrite_open']==1 ? "<li><a rel="nofollow noopener noreferrer" href='".$purl."/?typeid=".$this->TypeID."&q=".rawurldecode($oldkeyword)."&PageNo=$prepagenum'>上一页</a></li>\r\n" : "<li><a rel="nofollow noopener noreferrer" href='".$purl."/?typeid=".$this->TypeID."&q=".rawurldecode($oldkeyword)."&PageNo=$prepagenum'>上一页</a></li>\r\n"; $indexpage=$GLOBALS['rewrite_open']==1 ? "<li><a rel="nofollow noopener noreferrer" href='".$purl."/?typeid=".$this->TypeID."&q=".rawurldecode($oldkeyword)."&PageNo=1'>首页</a></li>\r\n" : "<li><a rel="nofollow noopener noreferrer" href='".$purl."/?typeid=".$this->TypeID."&q=".rawurldecode($oldkeyword)."&PageNo=1'>首页</a></li>\r\n"; } else { $indexpage="<li>首页</li>\r\n"; } if($this->PageNo!=$totalpage && $totalpage>1) { $nextpage.=$GLOBALS['rewrite_open']==1 ? "<li><a rel="nofollow noopener noreferrer" href='".$purl."/?typeid=".$this->TypeID."&q=".rawurldecode($oldkeyword)."&PageNo=$nextpagenum'>下一页</a></li>\r\n" : "<li><a rel="nofollow noopener noreferrer" href='".$purl."/?typeid=".$this->TypeID."&q=".rawurldecode($oldkeyword)."&PageNo=$nextpagenum'>下一页</a></li>\r\n"; $endpage=$GLOBALS['rewrite_open']==1 ? "<li><a rel="nofollow noopener noreferrer" href='".$purl."/?typeid=".$this->TypeID."&q=".rawurldecode($oldkeyword)."&PageNo=$totalpage'>末页</a></li>\r\n" : "<li><a rel="nofollow noopener noreferrer" href='".$purl."/?typeid=".$this->TypeID."&q=".rawurldecode($oldkeyword)."&PageNo=$totalpage'>末页</a></li>\r\n"; } else { $endpage="<li>末页</li>\r\n"; }
然后是数字链接:
//获得数字链接 $listdd=""; $total_list = $list_len * 2 + 1; if($this->PageNo >= $total_list) { $j = $this->PageNo - $list_len; $total_list = $this->PageNo + $list_len; if($total_list > $totalpage) { $total_list = $totalpage; } } else { $j=1; if($total_list > $totalpage) { $total_list = $totalpage; } } for($j; $j<=$total_list; $j++) { if($j == $this->PageNo) { $listdd.= "<li class='pagelist cur'>$j </li>\r\n"; } else { $listdd.=$GLOBALS['rewrite_open']==1 ? "<li class='pagelist'><a rel="nofollow noopener noreferrer" href='".$purl."/?typeid=".$this->TypeID."&q=".rawurldecode($oldkeyword)."&PageNo=$j'>".$j."</a> </li>\r\n" : "<li><a rel="nofollow noopener noreferrer" href='".$purl."/?typeid=".$this->ChannelType."&q=".rawurldecode($oldkeyword)."&PageNo=$j'>[".$j."]</a> </li>\r\n"; } } $plist = "<table border='0' cellpadding='0' cellspacing='0'>\r\n"; $plist .= "<tr align='center' style='font-size:10pt'>\r\n"; $plist .= "<form name='pagelist' action='".$this->GetCurUrl()."'>$hidenform"; $plist .= $infos; $plist .= $indexpage; $plist .= $prepage; $plist .= $listdd; $plist .= $nextpage; $plist .= $endpage; if($totalpage>$total_list) { $plist.="<td width='38'><input type='text' name='PageNo' style='width:28px;height:14px' value='".$this->PageNo."'/></td>\r\n"; $plist.="<td width='30'><input type='submit' name='plistgo' value='GO' style='width:30px;height:22px;font-size:9pt'/></td>\r\n"; } $plist .= "</form>\r\n</tr>\r\n</table>\r\n"; return $plist; }
以上代码是伪静态的基础上做的修改,请对比修改,改的都是 $prepage.=$GLOBALS['rewrite_open']==1 ? 后面的:
//比如数字链接我改的主要是这一段 "<li class='pagelist'><a rel="nofollow noopener noreferrer" href='".$purl."/?typeid=".$this->ChannelType."&q=".rawurldecode($oldkeyword)."&PageNo=$j'>".$j."</a> </li>\r\n" : "<li><a rel="nofollow noopener noreferrer" href='".$purl."/?typeid=".$this->TypeID."&q=".rawurldecode($oldkeyword)."&PageNo=$j'>[".$j."]</a> </li>\r\n";
到此,改完了。分页css样式:
.pagelist {padding:50px 0px;} .pagelist a{color:#fff} .pagelist .cur {padding: 5px 10px;background-color: #038b8e;color: #fff;font-size: 14px;margin: 0 1px;} .pagelist li{display:inline;padding: 5px 10px; background-color: #00cccb; color: #fff; font-size: 14px; margin: 0 1px;border-bottom: none;} .pagelist li:hover{background-color: #038b8e;} .pagelist span{display: inline-block;padding: .5em .8em;background-color: #f9f9f9;color: #999;} .pagelist .text{float: right; margin-right: 10px;color: #9e9e9e;}
以上就是DedeCMS搜索指定栏目的搜索伪静态方法。承受,继续承受。性命的重量是压在肩头的种种过往和经历。性命的好处,是在你快要趴下的时候咬牙抗住。性命的精彩,是你负重前行,最终到达你梦里以前到过的地方。更多关于DedeCMS搜索指定栏目的搜索伪静态方法请关注haodaima.com其它相关文章!