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') ?>
</article>
< ?php endwhile; ?>
< ?php endif; ?>
|
以上代码需要放入search.php文件中。
<!– Recent Posts –>
<div class="widget recent-posts">
<div class="entry-list w-thumbs">
<ul class="posts-list list-dividers">
<?php $posts = query_posts($query_string . '&posts_per_page=10');?>
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<li class="entry-li">
<article class="post-small clearfix">
<div class="entry-img">
<a href="<?php the_permalink() ?>">
<?php include( TEMPLATEPATH . '/thumbnail/archivethumbnail.php' ); ?>
</a>
</div>
<div class="entry">
<h3 class="entry-title"><a href="<?php the_permalink() ?>"><?php echo mb_strimwidth(get_the_title(), 0, 100,''); ?></a></h3>
<span class="listcon"><small> <?php if (has_excerpt()){ echo wp_trim_words( get_the_excerpt(), 55, '…' );} elseif (post_password_required()){echo wp_trim_words( get_the_content(), 22, '…' ); }else {echo wp_trim_words( get_the_content(), 55, '…' );} ?></small></span>
<ul class="entry-meta list-inline">
<li class="entry-date">
<a href="<?php the_permalink() ?>"><?php the_date_xml()?></a>
</li>
</ul>
</div>
</article>
</li>
<?php endwhile; ?>
<?php else : ?>
<li class="entry-li">
<article class="post-small clearfix">
<div class="entry">
<h3 class="entry-title"><a href="<?php bloginfo('home'); ?>">亲!没有您要找的,请此处返回首页!</a></h3>
</div>
</article>
</li>
<?php endif; ?>
</ul>
<?php wp_pagenavi(); ?>
</div>
</article>
</li>
</ul>
</div>
</div>
评论(0)
暂无评论