首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WordPress改性2搜索小部件,搜索不同的内容

WordPress改性2搜索小部件,搜索不同的内容
EN

Stack Overflow用户
提问于 2013-11-01 14:19:10
回答 1查看 147关注 0票数 0

我将Searchform.php修改为:

代码语言:javascript
复制
 'search_id' => 'id', 'form_action' => ( 'http://local.amleo.com/newps/pulldata.php'

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

下一个搜索Widget,我想搜索类别"AML热点主题“。不知道我怎么能做到。有什么主意吗?

所以你可以可视化:http://i.imgur.com/HSd9EEZ.png

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

我不是超级欺骗的PHP向导,但我可以非常体面地遵循指示。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-11-01 15:11:17

你不需要两个目标来搜索,相反你可以这样做

newps的一种形式

代码语言:javascript
复制
<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

代码语言:javascript
复制
<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文件,如下所示

代码语言:javascript
复制
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();
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19728607

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档