TODO: To change the header's content go to Dr.Explain menu Options : Project Settings : HTML (CHM) Export : Setup HTML Template and Layout
×
Menu
Index

Search

Chèn Form tìm kiếm trên website.
<?php get_search_form()?>
 
Hàm trên sẽ include template: searchform.php có nội dung như sau:
<form role="search" method="get" id="searchform" action="<?php bloginfo('siteurl'); ?>">
  <div>
  <input type="submit" id="searchsubmit" value="Search" />
    <label class="screen-reader-text" for="s">Search for:</label>
    <input type="text" value="" name="s" id="s" />
    in <?php wp_dropdown_categories( 'show_option_all=All Categories' ); ?>
  
  </div>
</form>
 
Lưu ý:
     + trường tìm kiếm có tên "s" xác định gọi vào template search.php
     + trang tìm kiếm có địa chỉ (base) thuộc trang chủ.
 
Form tìm kiếm nâng cao:
Tạo thêm các trường lựa chọn cho form chẳng hạn như tìm kiếm theo danh mục, ..và tùy biến tham số query để lấy kết quả theo giá trị người dùng tìm kiếm trên form với hook 'pre_get_posts'.
 
Tuy nhiên, wordpress cho bạn sử dụng sẵn các tham số đặc biệt như cat,..Ví dụ sau form tìm kiếm có thêm trường lựa chọn danh mục. Thêm thẻ select chứa danh sách categories vào trong nội dung form tìm kiếm ở trên.
<form>
..
<?php wp_dropdown_categories( 'show_option_all=All Categories' ); ?>
..
</form>
 
Made with help of Dr.Explain

Unregistered version