WordPress修改。 2搜索小部件,搜索不同的内容

时间:2013-11-01 14:19:10

标签: php wordpress forms

我将Searchform.php修改为:

 'search_id' => 'id', 'form_action' => ( 'http://local.amleo.com/newps/pulldata.php'

对于第一个“搜索”窗口小部件,转到显示其他内容结果的自定义PHP页面。

下一个搜索小工具,我想搜索“AML热门话题”类别。不知道我怎么能这样做。任何想法??

所以你可以想象:http://i.imgur.com/HSd9EEZ.png

第一次搜索是我为Searchform.php修改的。第二个是我不确定的。

我无论如何都不是超级聪明的PHP向导,但我可以非常正确地遵循指示。

1 个答案:

答案 0 :(得分:1)

你不需要两个搜索目标,而是可以使用类似的东西

newps

的一种表单
<form method="get" id="searchform" action="<?php echo esc_url( home_url() ); ?>">
    <input type="text" value="<?php echo esc_attr( get_search_query() ); ?>" name="s" id="s" />
    <input type="hidden" value="newps" name="key" />
    <input type="submit" id="searchsubmit" value="<?php esc_attr_e('Search','Aggregate'); ?>" />
</form>

AML的另一个

<form method="get" id="searchform" action="<?php echo esc_url( home_url() ); ?>">
    <input type="text" value="<?php echo esc_attr( get_search_query() ); ?>" name="s" id="s" />
    <input type="hidden" value="aml" name="key" />
    <input type="submit" id="searchsubmit" value="<?php esc_attr_e('Search','Aggregate'); ?>" />
</form>

在主题的根文件夹中创建一个search.php文件,如下所示

get_header();

// if you get `key` then it will be your custom search
// otherwise, default search will be performed
if(!empty($_GET['key'])) {
    $key = $_GET['key']; // it will be either 'newps' or 'aml'
    $search = $_GET['s'];
    // modify the query using your $key and $search param
    query_posts(...);
}

if (have_posts()) :
    while(have_posts()): the_post();
        // the_title() and more...
    endwhile;
endif;
// reset the query if modified
if(!empty($key)) wp_reset_query();

get_sidebar();
get_footer();