2016-08-23 14 views
0

3つのブログ投稿をすべて隣の行に表示しようとしています。次の行には1つのブログ投稿、次の3つの行だけが表示されますそうです。私はどのように3つの投稿を取得し、1を得る方法を考え出しましたが、3つの投稿については2つの投稿だけが並び、3つ目の投稿は次の行に置かれます。私はブログの幅を広げようとしましたが、うまくいかなかったのです。誰にも解決策はありますか?ここで1行に3つの投稿と1つの投稿

は私のindex.phpファイルは、私はコードを正しく読んでいる場合は、あなたのグリッドは(単一の行がcol-md-12さに基づいて)12列があり

<?php 
 
/* 
 
* Template Name: learningwordpress 
 
*/ 
 
    
 
get_header(); 
 
    
 
$i = 0; 
 
    
 
$args = array(
 
    'posts_per_page' => 7, 
 
    'paged' => 1 
 
); 
 
    
 
$the_query = new WP_Query($args); 
 
    
 
if ($the_query->have_posts()) { 
 
    while ($the_query->have_posts()) { 
 
    
 
     if($i %2 == 1) { 
 
      $the_query->the_post(); ?> 
 
      <article class="post col-md-12"> 
 
       <?php the_post_thumbnail('large-thumbnail'); ?> 
 
       <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> 
 
       <p> 
 
        <?php echo get_the_excerpt(); ?> 
 
        <a class="moretext" href="<?php the_permalink(); ?>">Read more</a> 
 
       </p> 
 
      </article> 
 
      <?php 
 
     } 
 
     else { 
 
      $the_query->the_post(); ?> 
 
      <article class="post col-md-6"> 
 
       <?php the_post_thumbnail('medium-thumbnail'); ?> 
 
       <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> 
 
       <p> 
 
        <?php echo get_the_excerpt(); ?> 
 
        <a class="moretext" href="<?php the_permalink(); ?>">Read more</a> 
 
       </p> 
 
      </article>  
 
      <?php $the_query->the_post(); ?> 
 
      <article class="post col-md-6"> 
 
       <?php the_post_thumbnail('medium-thumbnail'); ?> 
 
       <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> 
 
       <p> 
 
        <?php echo get_the_excerpt(); ?> 
 
        <a class="moretext" href="<?php the_permalink(); ?>">Read more</a> 
 
       </p> 
 
      </article> 
 
<?php $the_query->the_post(); ?> 
 
      <article class="post col-md-6"> 
 
       <?php the_post_thumbnail('medium-thumbnail'); ?> 
 
       <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> 
 
       <p> 
 
        <?php echo get_the_excerpt(); ?> 
 
        <a class="moretext" href="<?php the_permalink(); ?>">Read more</a> 
 
       </p> 
 
      </article> 
 
      <?php 
 
     } 
 
     ?> 
 
     <?php 
 
     $i++; 
 
    } 
 
} 
 
else { 
 
    echo '<p>Sorry, no posts matched your criteria.</p>'; 
 
} 
 
get_footer();

答えて

0

です。行ごとに3列に分割するには、col-md-4が必要です。記事クラスにはcol-md-6ではありません。

+0

ありがとうございました! – user6738171

+0

問題ありません。私の答え(それの横にあるチェックマークを押してください)やアップヴォートを受け入れることは自由です。ここで感謝の気持ちを伝えています。 – Hobo

+0

ありがとうございます;とても有難い! – Hobo

関連する問題