2016-04-14 48 views
0

我有一個WP插件可以發佈搜索結果。這是效果PHP:我希望搜索結果顯示在列中,但只有文字確實

<?php 
/** 
* Search & Filter Pro 
* 
* Sample Results Template 
* 
* @package Search_Filter 
* @author Ross Morsali 
* @link  http://www.designsandcode.com/ 
* @copyright 2015 Designs & Code 
* 
* Note: these templates are not full page templates, rather 
* just an encaspulation of the your results loop which should 
* be inserted in to other pages by using a shortcode - think 
* of it as a template part 
* 
* This template is an absolute base example showing you what 
* you can do, for more customisation see the WordPress docs 
* and using template tags - 
* 
* http://codex.wordpress.org/Template_Tags 
* 
*/ 


if ($query->have_posts()) 
{ 

    ?> 

    Found <?php echo $query->found_posts; ?> Results<br /> 
    Page <?php echo $query->query['paged']; ?> of <?php echo $query->max_num_pages; ?><br /> 


    <div class="pagination"> 

     <div class="nav-previous"><?php next_posts_link('Older posts', $query->max_num_pages); ?></div> 
     <div class="nav-next"><?php previous_posts_link('Newer posts'); ?></div> 
     <?php 
      /* example code for using the wp_pagenavi plugin */ 
      if (function_exists('wp_pagenavi')) 
      { 
       echo "<br />"; 
       wp_pagenavi(array('query' => $query)); 
      } 
     ?> 
    </div> 

    <?php 
    while ($query->have_posts()) 
    { 
     $query->the_post(); 

     ?> 

<div> 
      <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> 
      <?php 
       if (has_post_thumbnail()) { 
        echo '<p>'; 
        the_post_thumbnail("small"); 
        echo '</p>'; 
       } 
      ?> 
      <p><br /><?php the_excerpt(); ?><p> 
</div> 

     <?php 
    } 
    ?> 
    Page <?php echo $query->query['paged']; ?> of <?php echo $query->max_num_pages; ?><br /> 

    <div class="pagination"> 

     <div class="nav-previous"><?php next_posts_link('Older posts', $query->max_num_pages); ?></div> 
     <div class="nav-next"><?php previous_posts_link('Newer posts'); ?></div> 
     <?php 
      /* example code for using the wp_pagenavi plugin */ 
      if (function_exists('wp_pagenavi')) 
      { 
       echo "<br />"; 
       wp_pagenavi(array('query' => $query)); 
      } 
     ?> 
    </div> 
    <?php 
} 
else 
{ 
    echo "No Results Found"; 
} 

?> 

現在我想要的結果(職位)出現在2列,但是,當我試試這個:

<div class="container"> 
    <div class="row"> 
     <div class="col-md-2"> 
      <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> 
      <?php 
       if (has_post_thumbnail()) { 
        echo '<p>'; 
        the_post_thumbnail("small"); 
        echo '</p>'; 
       } 
      ?> 
      <p><br /><?php the_excerpt(); ?><p> 
</div> 
</div> 
</div> 

我可以看到文本(P)出現在列中,但不是結果。

我究竟如何實現我的目標?

+0

請看截圖? –

+0

由於某種原因,它沒有保存我的編輯。我編輯了它,第二段代碼在原始答案中是錯誤的。 – user3078100

+0

這是我得到的結果:http://prntscr.com/as53eg 我希望帖子結果自己排列在列中,而不是文本。 – user3078100

回答

1

有幾個錯誤。 第一個col-md-2使12列布局中的2列寬。所以這是六分之一而不是一半。它應該是col-md-6

然後下一個問題是你添加一個容器,行和列的每個帖子。但你應該只有一個容器和一排。對於每篇文章,您應該製作專欄div。

<!-- 1 container and row --> 
<div class="container"> 
<div class="row">  
<?php 
    while ($query->have_posts()){ 
    $query->the_post(); 
?> 
    <!-- a six column wide div for each post --> 
    <div class="col-md-6"> 
     <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> 
     <?php 
     if (has_post_thumbnail()) { 
      echo '<p>'; 
      the_post_thumbnail("small"); 
      echo '</p>'; 
     } 
     ?> 
     <p><br /><?php the_excerpt(); ?><p> 
    </div> 

<?php 
    } 
?> 
</div> 
</div> 
+0

這樣做了!感謝您的幫助。 – user3078100