2017-03-06 6 views
1

私はブートストラップとワードプレスをマージし、私はこのような何かを得る必要を示していけません。次はループでブログを表示しています...しかし、その空のボックスを表示...Wordpressのは、ブログページがブログ

どうしたのですか? これを行うにはより良い方法がありますか?

<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変数を印刷したい場合、私は、コードの上に示されているいるよう、それを使用する必要があります。

THank you

関連する問題