2017-06-20 48 views
0

由於某種原因,我得到的搜索欄重複。 我懷疑我有一個雙重功能命令的地方...但我找不到它。有人可以用「新鮮的眼睛」來看代碼並嘗試找到我的錯誤嗎? 爲WordPress的一直給我2個搜索欄,而不是一個 我使用記事本+ +,引導3.0版本和WordPress 4.7.8搜索欄一式兩份(wordpress/php/bootstrap)

下面是代碼

<?php get_header(); ?> 

<div class="row"> 

    <div class="col-xs-12 col-sm-8"> 

     <div class="row text-center no-margin"> 

     <?php 
     $currentPage = (get_query_var('paged')) ? get_query_var('paged') : 1; 
     $args = array('posts_per_page' => 3,'post_type'=>'post', 'paged' => $currentPage); 
     new WP_Query($args); 
     if(have_posts()): $i = 0; 

      while(have_posts()): the_post(); ?> 

       <?php 
        if($i==0): $column = 12; $class = ''; 
        elseif($i > 0 && $i <= 2): $column = 6; $class = ' second-row-padding'; 
        elseif($i > 2): $column = 4; $class = ' third-row-padding'; 
        endif; 

       ?> 
        <?php the_content(); ?> 

        <div class="col-xs-<?php echo $column; echo $class; ?> blog-item"> 
         <?php if(has_post_thumbnail()): 
          $urlImg = wp_get_attachment_url(get_post_thumbnail_id(get_the_ID())); 
         endif; ?> 
         <div class="blog-element" style="background-image: url(<?php echo $urlImg; ?>);"> 

          <!--<?php the_title(sprintf('<h1 class="entry-title"><a href="%s">', esc_url(get_permalink())),'</a></h1>'); ?> --> 
          <h1 class="entry-title"><?php the_title(); ?></h1> 

          <small><?php the_category(' '); ?></small> 
         </div> 
        </div> 

      <?php $i++; endwhile; ?> 

      <div class="col-xs-6 text-left"> 
       <?php next_posts_link('« Older Posts'); ?> 
      </div> 
      <div class="col-xs-6 text-right"> 
       <?php previous_posts_link('Newer Posts »'); ?> 
      </div> 

     <?php endif; 
       wp_reset_query(); 
     ?> 
     </div> 

    </div> 

    <div class="col-xs-12 col-sm-4"> 
     <?php get_sidebar(); ?> 
    </div> 

</div> 

<?php get_footer(); ?> 
+0

你的代碼似乎有缺少的部分(而不是真正格式化)。順便說一句,你使用了什麼樣的模板(如果它是你的自定義模板,請包括搜索欄被調用的部分)? – Kaddath

+0

」> \t 「name =」s「title =」Search「/>

+0

yeas我正在使用自定義模板。該代碼是從我的index.php,我已經明白,它是「模板的核心」 –

回答

1

試試這個代碼。

我已禁用//get_sidebar();

 <?php get_header(); ?> 

<div class="row"> 

    <div class="col-xs-12 col-sm-8"> 

     <div class="row text-center no-margin"> 

     <?php 
     $currentPage = (get_query_var('paged')) ? get_query_var('paged') : 1; 
     $args = array('posts_per_page' => 3,'post_type'=>'post', 'paged' => $currentPage); 
     new WP_Query($args); 
     if(have_posts()): $i = 0; 

      while(have_posts()): the_post(); ?> 

       <?php 
        if($i==0): $column = 12; $class = ''; 
        elseif($i > 0 && $i <= 2): $column = 6; $class = ' second-row-padding'; 
        elseif($i > 2): $column = 4; $class = ' third-row-padding'; 
        endif; 

       ?> 


        <div class="col-xs-<?php echo $column; echo $class; ?> blog-item"> 
         <?php if(has_post_thumbnail()): 
          $urlImg = wp_get_attachment_url(get_post_thumbnail_id(get_the_ID())); 
         endif; ?> 
         <div class="blog-element" style="background-image: url(<?php echo $urlImg; ?>);"> 

          <!--<?php the_title(sprintf('<h1 class="entry-title"><a href="%s">', esc_url(get_permalink())),'</a></h1>'); ?> --> 
          <h1 class="entry-title"><?php the_title(); ?></h1> 

          <?php the_content(); ?> 

          <small><?php the_category(' '); ?></small> 
         </div> 
        </div> 

      <?php $i++; endwhile; ?> 

      <div class="col-xs-6 text-left"> 
       <?php next_posts_link('« Older Posts'); ?> 
      </div> 
      <div class="col-xs-6 text-right"> 
       <?php previous_posts_link('Newer Posts »'); ?> 
      </div> 

     <?php endif; 
       wp_reset_query(); 
     ?> 
     </div> 

    </div> 

    <div class="col-xs-12 col-sm-4"> 
     <?php //get_sidebar(); ?> 
    </div> 

</div> 
+0

非常感謝它!你救了我的一天! :) @vel –

+0

很高興爲您提供幫助。你以前的問題截圖幫助找出問題。 – vel