Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用搜索框搜索我的WordPress网站页面_Wordpress_Search Box - Fatal编程技术网

如何使用搜索框搜索我的WordPress网站页面

如何使用搜索框搜索我的WordPress网站页面,wordpress,search-box,Wordpress,Search Box,如何使用放置在网站中的搜索框搜索WordPress网站页面? 目前我正在使用这个代码 <form id="searchform" method="get" action="<?php bloginfo('siteurl')?>/" style="margin-left: -43px;"> <input type="text" name="" id="s" class="textbox" placeholder="Search" required/>

如何使用放置在网站中的搜索框搜索WordPress网站页面? 目前我正在使用这个代码

<form id="searchform" method="get" action="<?php bloginfo('siteurl')?>/" style="margin-left: -43px;">
    <input type="text" name="" id="s" class="textbox" placeholder="Search" required/>
    <input id="btnSearch" type="submit" name="submit" value="<?php _e('Search'); ?>" />
</form>
我使用了name=s,但它不能正确搜索。我想,如果用户权限page1名称搜索框将其带到siteurl/page1,然后再带到page2和剩余页面

提前感谢

试试这个:

    function redirect_search() {
        if (is_search() && !empty($_GET['s'])) {
            wp_redirect(home_url("/").urlencode($_GET['s']));
            exit();
        }
    }
    add_action('template_redirect', 'redirect_search' );
在functions.php文件中添加上述代码

所以现在当你输入一些东西时,它会将它重定向到那个页面

注意:如果您键入与已发布帖子相关的内容,它将重定向到该帖子,而不是您输入的内容

例如:如果我在搜索框中键入hello,它会将您重定向到hello World,这是wordpress安装过程中出现的默认帖子


这就是我为您准备的。

您确定要这样做吗?因为它可能会导致用户进入404页,因为用户通常对此一无所知。
<div id="content" class="textbox <?php echo of_get_option('blog_sidebar_pos') ?>">
 <?php _e('Search for:',''); ?> "<?php the_search_query(); ?>"

    <?php 

        if (have_posts()) : while (have_posts()) : the_post(); 

                $format = get_post_format();
                get_template_part( 'include/'.$format );

                if($format == '')
                get_template_part( 'include/standard' );

         endwhile; else:

         ?>

            <?php echo '<p><strong>' . __('There has been an error.', '') . '</strong></p>'; ?>
            <p> <a href="<?php bloginfo('url'); ?>/" title="<?php bloginfo('description'); ?>"><?php _e('return to home page', ''); ?></a> <?php _e('use the search .', ''); ?></p>
            <?php get_search_form(); ?>
        </div><!--no-results-->

    <?php endif; ?>

  <?php get_template_part('include/post'); ?>