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') ?> //Vevb.com
- </article>
- < ?php endwhile; ?>
- < ?php endif; ?>
以上代碼需要放入search.php文件中.
新聞熱點
疑難解答
圖片精選