Bootstrap / Wordpress:带有空格值的搜索表单显示来自导航的代码

Bootstrap / Wordpress:带有空格值的搜索表单显示来自导航的代码

问题描述:

I'm working on a Wordpress page using the Bootstrap framework. The normal search function works just fine, but if I search for spaces (" ") or words with a space in the beginning or end it totally messes up my navigation on the page - the html code is displayed on the site and I think the search function searches for values in my navigation.

I tried to solve this by creating the search.php and header.php as new but that didn't work. As I used Bootstrap to create the page I had some issues changing the code for the Wordpress templates and it's possible that there could be the cause.

HTML code from my header.php file:

<div id="searchBox" class="col-lg-2 col-lg-offset-4">
   <div class="form-group">
       <div class="icon-addon addon">
           <form method="get" id="searchform" action="<?php echo $_SERVER['PHP_SELF']; ?>">
           <input id="searchField" type="text" value="<?php echo wp_specialchars($s, 1); ?>" name="s" id="s" placeholder="Search..." class="form-control">
           <label id="searchIcon" for="search" class="glyphicon glyphicon-search" rel="tooltip" title="Search..."></label>
           </form>
        </div>
   </div>
</div>

Code from my search.php file:

    <?php if (have_posts()) : ?>
<div class="row">
   <content class="searchContent col-lg-7">
      <div id="leftContent" class="col-lg-10 col-lg-offset-1 col-xs-12">
        <?php while (have_posts()) : the_post(); ?>
        <h1><a href="?php the_permalink()?"><?php the_title(); ?></a></h1>
        <div class="entry">
          <?php the_excerpt(); ?>
        </div>
     <?php endwhile; ?>

      <p align="center"><?php next_posts_link('&laquo; &Auml;ltere Eintr&auml;ge') ?> | <?php previous_posts_link('Neuere Eintr&auml;ge &raquo;') ?></p>
      </div>
   </content>
      <aside class="col-lg-3">
          <?php get_sidebar(); ?>
      </aside>
  </div>
<?php else : ?>
<div class="row">
  <div id="siteTitle" class="col-lg-6 ">
    <div  id="titleText" class="info col-lg-offset-11">
      <h1>Nothing found</h1>
    </div>
</div>

Can you help me solve this issue? I tried for hours and days but haven't found a solution yet. Here an image of what my nav looks like if I search for values with spaces.

There is an error in the code you are using to highlight search terms in the copy.

When I search test a test, the letter A is made bold anywhere in the search results, as well as in the main nav. (It is wrapped with <strong class="search-excerpt"></strong>).

If I search test g test, the letter G is made bold. I think your site is not handling the $_GET values correctly, since it is only using the second value in the $_GET['s'] array.

Searching your theme's codebase for <strong class="search-excerpt"> should at least point you in the right direction of where the error is coming from.

As discussed in comments, problem was caused by a custom theme, not aforementioned search form and search.php modifications.