好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

wordpress自定义搜索框和结果页面的方法 - WordPre

wordpress自定义搜索框和结果页面的方法

WordPress是一种使用PHP语言开发的博客平台,用户可以在支持PHP和MySQL数据库的服务器上架设属于自己的网站。也可以把 WordPress当作一个内容管理系统(CMS)来使用了,现在在国内很多个人站长都使用wordpress做自己的个人博客了,下文小编就为各位介绍wordpress自定义搜索框和结果页面的教程,希望例子能帮助到大家。

对于在某个主题中想添加很多自己想要的效果给搜索框和结果页面的人来说这绝对是一个好的方案,其实代码很简单而且很少,关键是几个要注意的地方。

首先是搜索框的代码如下:

< form   role = "search"   method = "get"   id = "searchform"   action = "<?php echo home_url( '/' ); ?>" >        < input   class = "letterinput"   type = "text"   name = "s"   value = "Search"   />        < input   class = "gobutton"   type = "submit"   value = "Go"   />   </ form >  

将以上代码放入自己想要的地方并自己编写好样式就可以了,接着就是结果页面的代码,代码如下:

<?php  $posts =query_posts( $query_string  . '&posts_per_page=20' ); ?>  <?php  if  (have_posts()) : ?>      <h2>Search Results</h2>  < ?php  while  (have_posts()) : the_post(); ?>      <article  class = "searchlist clearfix" >          <a href= "<?php the_permalink() ?>"  rel= "bookmark"  title= "Permanent Link to < ?php the_title_attribute(); ?>" >< ?php the_title(); ?></a>          <br />Posted in < ?php the_category( ', ' ) ?> on < ?php the_time( 'l jS F, Y - g:ia' ) ?>   //phpfensi.com        </article>  < ?php  endwhile ; ?>  < ?php  endif ; ?> 

以上代码需要放入search.php文件中.

查看更多关于wordpress自定义搜索框和结果页面的方法 - WordPre的详细内容...

  阅读:63次