A-A+

wordpress自定义搜索页面

2015年02月01日 PHP开源系统 评论 1 条 阅读 126 views 次

当自己的博客内容越来越多的时候,站内搜索就会显得越发重要了,而我们想要的就是搜索出其相关的内容,有时候 wordpress 默认主题常规的搜索页并不是我们想要的,这个时候就可以自定义搜索页面和结果页面了,改成自己喜欢的样式。

1,搜索框代码:

搜索框的样式看起来更简单一些,只需要把 form 表单做得好看一些就可以了,可以直接使用 DIV+CSS 来进行控制,下面是搜索框代码:

<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>

2,搜索结果代码:

搜索结果是展示搜索出来的相关内容了,这个也是可以用CSS样式来进行控制的,完整的搜索结果代码如下:

<?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') ?>
</article>
<?php endwhile; ?>
<?php endif; ?>

将其代码放入到 search.php 文件中即可。

标签:

1 条留言  访客:1 条  博主:0 条

  1. Chinaferien

    老师您好!我对我的网站www.chinaferien.com的搜索结果页面有两点疑问。第一:搜索结果页面url为http://www.chinaferien.com/?s= 而不是http://www.chinaferien.com/search,这样是否不利于SEO?第二:我的搜索结果页面效果不是很好,我希望我的搜索页面为http://www.chinaferien.com/archive-tours/top-10/ 这样的模板,但是搜索出来一直是http://www.chinaferien.com/?s=peking 的效果。左边图片还在,但是右边的文字就显得凌乱。还望老师在百忙之中抽空赐教,不甚感激!祝老师一切顺利!生活愉快!

给我留言