douchengjue9892 2016-12-29 14:33
浏览 64
已采纳

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.

  • 写回答

2条回答 默认 最新

  • dongzhijing8202 2016-12-29 15:35
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算