07 Ağustos 2009

Searching in A Selected Category

WordPress Yorum Ekle

WordPress searching system is'nt usefull. When you search something, it searches in posts, pages. It begins many unnecassary results. But if we can allow our visitors to select a category for their searching by creating a custom search form has a category dropdown list, i think it will be more usefull.
To do this, add theese codes in where you want to show your search form:

  1. <?php
  2. $search_form = '<form role="search" method="get" id="searchform" action="' . get_option('home') . '/" >
  3.     <div><label class="screen-reader-text" for="s">' . __('Search for:') . '</label>
  4.     <input type="text" value="' . esc_attr(apply_filters('the_search_query', get_search_query())) . '" name="s" id="s" />
  5.     <input type="submit" id="searchsubmit" value="'. esc_attr__('Search') .'" />
  6.  <br />'.
  7.   wp_dropdown_categories('show_option_all='.__('All Categories').'&hierarchical=1&echo=0')
  8.     .
  9.     '</div>
  10.     </form>';
  11. echo $search_form;
  12. ?>

Of course, you can customize the form using CSS as you want.
See at top of my sidebar. You can it (Notice: 'All Categories' means 'Tüm Kategoriler' and 'Search' means 'Ara' in Turkish).
I am sorry, i have a poor English.

Bu yazının kısa bağlantısı http://www.yakupgovler.com/?p=971.

Yazılarımı RSS aboneliği ile takip edebilir, yeni yazılarıma kolaylıkla ulaşabilirsiniz. Bunun için ise RSS adresimi kullanabilirsiniz.