2017-03-06 114 views
1

我與合併引導WordPress的,我希望得到的東西是這樣的:WordPress的,博客頁面不顯示博客

1| 
| 2 
3| 

我檢查是否有後(有3在那一刻)。接下來是循環,並顯示博客...但其顯示空箱...

我做錯了什麼? 或者也許有更好的方法來做到這一點?

<div class="wrapper"> 

    <?php 
     $rest_query = new WP_Query(array(
      'orderby' => 'post_date', 
      'order' => 'DESC', 
      'post_type' => array('post'), 
      'post_status' => 'publish' 
    )); 

    if($rest_query->have_posts()): 
    ?> 

    <?php while($rest_query->have_posts()): $rest_query->the_post(); ?> 

    <?php 
     if ($rest_query->current_post == 0) 
     { 
      echo '<div class="row"> 
      <div class="col-md-6"> 
       <div class="single first-post"> 
        <a href="<?php the_permalink(); ?>"><div class="thumb"><?php the_post_thumbnail(); ?></div></a> 
        <div class="content"> 
         <a href="<?php the_permalink(); ?>"><h1><?php the_title(); ?></h1></a> 
         <div class="data"> 
          <p class="date"><?php echo get_the_date();s ?></p> 
          <p class="social">0 shares/0 comments</p> 
         </div> 
        </div> 
       </div> 
      </div> 
      <div class="middleLine"></div> 
      <div class="col-md-6"></div> 
     </div>'; 
     } 
     elseif ($rest_query->current_post == 1) 
     { echo '<div class="row"> 
      <div class="col-md-6"></div> 
      <div class="middleLine"></div> 
      <div class="col-md-6"> 
       <div class="single secound-post"> 
         <a href="<?php the_permalink(); ?>"><div class="thumb"><?php the_post_thumbnail(); ?></div></a> 
         <div class="content"> 
          <a href="<?php the_permalink(); ?>"><h1><?php the_title(); ?></h1></a> 
          <div class="data"> 
           <p class="date"><?php echo get_the_date();s ?></p> 
           <p class="social">0 shares/0 comments</p> 
          </div> 
         </div> 
       </div> 
      </div> 
     </div>'; } 
    ?> 

    <?php endwhile; ?> 

    <?php endif; ?> 
</div> 

回答

1

我認爲你的代碼在頁面顯示時有一些錯誤。當你使用ECHO時,你不應該在裏面使用PHP標籤,這就是爲什麼它不適合你的情況。

修改你的代碼:

<div class="wrapper"> 

<?php 
    $rest_query = new WP_Query(array(
     'orderby' => 'post_date', 
     'order' => 'DESC', 
     'post_type' => array('post'), 
     'post_status' => 'publish' 
)); 

if($rest_query->have_posts()): 
?> 

<?php while($rest_query->have_posts()): $rest_query->the_post(); ?> 

<?php 
    if ($rest_query->current_post == 0) 
    { 
     echo '<div class="row"> 
     <div class="col-md-6"> 
      <div class="single first-post"> 
       <a href="'.the_permalink().'"><div class="thumb">'.the_post_thumbnail().'</div></a> 
       <div class="content"> 
        <a href="'.the_permalink().'"><h1>'.the_title().'</h1></a> 
        <div class="data"> 
         <p class="date">'.get_the_date().'</p> 
         <p class="social">0 shares/0 comments</p> 
        </div> 
       </div> 
      </div> 
     </div> 
     <div class="middleLine"></div> 
     <div class="col-md-6"></div> 
    </div>'; 
    } 
    elseif ($rest_query->current_post == 1) 
    { echo '<div class="row"> 
     <div class="col-md-6"></div> 
     <div class="middleLine"></div> 
     <div class="col-md-6"> 
      <div class="single secound-post"> 
        <a href="'.the_permalink().'"><div class="thumb">'.the_post_thumbnail().'</div></a> 
        <div class="content"> 
         <a href="'.the_permalink().'"><h1>'.the_title().'</h1></a> 
         <div class="data"> 
          <p class="date">'.get_the_date().'</p> 
          <p class="social">0 shares/0 comments</p> 
         </div> 
        </div> 
      </div> 
     </div> 
    </div>'; } 
?> 

<?php endwhile; ?> 

<?php endif; ?> 

注意:如果你要打印任何PHP變量,那麼它應該被用來作爲我已經在上面的代碼所示。

謝謝你