Skip to main content

八、wordpress搜索页调用标签

1、自定义wordpress模板主题搜索框制作

wordpress自定义全站搜索框
<form class="search-form" method="get" action="<?php bloginfo('home'); ?>"> 
       <input type="text" placeholder="搜索..." name="s" /> 
       <button type="submit"> <i class="iconfont icon-search"></i> </button> 
</form>
 
wordpress自定义搜索指定栏目分类  (value="" 为指定分类的id)
<form class="search-form" method="get" action="<?php bloginfo('home'); ?>"> 
       <input type="text" placeholder="搜索..." name="s" /> 
        <input type="hidden" name="cat" value="4,11,9,22,20,10,18,14,12,13,1" />
       <button type="submit"> <i class="iconfont icon-search"></i> </button> 
</form>
 
wordpress自定义不搜索该分类下的文章  (value="" 为指定分类的id)
<form class="search-form" method="get" action="<?php bloginfo('home'); ?>"> 
       <input type="text" placeholder="搜索..." name="s" /> 
       <input type="hidden" name="cat" value="-4,-11,-9,-22" />
       <button type="submit"> <i class="iconfont icon-search"></i> </button> 
</form>

 

2、wordpress搜索页search.php制作

获取搜索词
<? echo get_search_query()?>
搜索列表页 方法一 直接使用分类列表页循环方式即可
搜索列表页 方法二
       <?
		if(have_posts()){
		while(have_posts() ){
		the_post();
		?>
 
       <li> 
        <div class="shijian">
         <?php the_time('y-m') ?>
         <span><?php the_time('d') ?></span>
        </div> <a href="<?php the_permalink(); ?>" title="<?php the_title();?>"><?php the_title();?></a> 
		<p><? the_excerpt(); ?></p>
		<p></p>
	  </li> 
	 <? }
	
		}else{
			echo "没有搜索到文章";
		}
	?>