A-A+

wordpress自定义搜索页面

2015年02月01日 编程技术 暂无评论

当自己的博客内容越来越多的时候,站内搜索就会显得越发重要了,而我们想要的就是搜索出其相关的内容,有时候 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 文件中即可。

标签:

给我留言