wordpress搜索页制作和调用的方法
当网站内容比较多的时候,搜索页就显得非常重要了。
今天给大家介绍wordpress搜索页的制作方法,
在没有搜索内容的时候调用不同模板来显示。
在search.php页面中加入如下代码:
<?php if ( have_posts() ) : ?> <?php while ( have_posts() ) : the_post(); ?> <div><a href="<?php echo get_permalink($post->ID); ?>"><?php the_title(); ?></a></div> <?php endwhile; ?> <?php else : ?> <article> <header class="entry-header"> <h1 class="entry-title"><?php _e( '没有找到该文章', 'leizi' ); ?></h1> </header> <div class="entry-content"> <p><?php _e( '抱歉没有找到该文章', 'leizi' ); ?></p> <?php get_search_form(); ?> </div> </article> <?php endif; ?>
搜索关键的调用:
<?php the_search_query() ?>
搜索框的调用:
<form method="get" id="searchform" action="<?php bloginfo('url'); ?>/"> <div> <input type="text" value="<?php the_search_query(); ?>" name="s" id="s" /> <input type="submit" id="searchsubmit" value="Search" /> </div> </form>
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END