
WordPress 高階搜尋設計 : WordPress 按分類搜尋
WordPress 按分類搜尋目前很少人在用,99% 的 WordPress 都是用普通的搜尋方式,程式碼如下:
| <form action=」<?php bloginfo(『url』); ?>」 method=」get」 id=」search」> <input name=」s」 type=」text」 /> <input type=」submit」 value=」" /> </form> |
![]()
個人還是比較喜歡高階的搜尋方法,按分類進行搜尋,程式碼如下:
| <form id=」searchform」 name=」searchform」 method=」get」 action=」<?php bloginfo(『home』); ?>/」 > <ul> <li> <p> <?php $select = wp_dropdown_categories(『class=search_select&show_option_all=全站搜尋&orderby=name&hierarchical=0&selected=-1&depth=1′);?> </p> </li> <li> <input type=」text」 name=」s」 id=」s」 maxlength=」34″ value=」"/> </li> <li> <input type=」image」 value=」" src=」<?php bloginfo(『template_url』); ?>/img/search.gif」/> </li> </ul> </form> |

WordPress 還有另外一種方法實現高階搜尋,選項框選擇的高階搜尋,這個需要 WordPress 設計者手動填寫分類的 ID,這種搜尋的原始碼如下:
| <div> <form id=」index_search」 name=」index_search」 method=」get」 action=」<?php bloginfo(『home』); ?>/」> <p><input type=」text」 name=」s」 id=」s」 value=」"/> <input type=」submit」 value=」 搜 索 」 /></p> <p> <label for=」s_type5″ style=」width:50px」><input type=」radio」 name=」cat」 id=」cat」 value=」all」 checked> 全站</label> <label for=」s_type1″ style=」width:50px」><input type=」radio」 name=」cat」 id=」cat」 value=」4″ checked> 主題</label> <label for=」s_type2″ style=」width:50px」><input type=」radio」 name=」cat」 id=」cat」 value=」6″> 外掛</label> <label for=」s_type3″ style=」width:50px」><input type=」radio」 name=」cat」 id=」cat」 value=」3″> 主機</label> <label for=」s_type4″ style=」width:50px」><input type=」radio」 name=」cat」 id=」cat」 value=」10″> 經驗</label> </p> </form> </div> |
