サポート » 使い方全般 » 横並びに交互に並べた投稿のループ

  • 質問させてください。
    現在、以下のような形でループを作成しています。

    <?php if(have_posts()) : while (have_posts()) : the_post(); ?>
    
    <table class="seeTbl" cellspacing="0">
    
    <tr valign="top">
    
    <!--左-->
    <td width="80"><?php $image1 = post_custom('写真');
    echo wp_get_attachment_image( $image1,'thumbnail' ); ?></td>
    <td valign="top" width="250">
    <a href="detail.html"><?php the_title();?></a><br />
    <?php the_content();?></td>
    <!--左-->
    
    <td><img src="/images/spacer.gif" width="10" height="1"></td>
    
    <!--右-->
    <td width="80"><?php $image1 = post_custom('写真');
    echo wp_get_attachment_image( $image1,'thumbnail' ); ?></td>
    <td valign="top" width="250">
    <a href="detail.html"><?php the_title();?></a><br />
    <?php the_content();?></td>
    <!--右-->
    
    </tr>
    
    </table>
    
    <?php endwhile; endif; ?>

    上記を実行しますと、当然なのですが左も右も同じ投稿の内容が表示されて、ループしてしまいます。

    これを左右に別々の投稿を表示しながらループさせていくにはどうしたら良いのでしょうか?
    イメージとしましては、

    1 2
    3 4
    5 6
    7 8
    .
    .

    ↑このように交互に順番に表示していきたいと思っています。

    良い解決法をご存知の方がいらっしゃいましたらご教授ください。
    よろしくお願いします。

2件の返信を表示中 - 1 - 2件目 (全2件中)
  • 試してないのですが

    <?php $cnt=1 ?>
    <?php if(have_posts()) : ?>
    <table class="seeTbl" cellspacing="0">
    
    <?php while (have_posts()) : the_post(); ?>
    
    <?php if ($cnt == 1){ ?>
    <tr valign="top">
    <?php } ?>
    
    <td width="80"><?php $image1 = post_custom('写真');
    echo wp_get_attachment_image( $image1,'thumbnail' ); ?></td>
    <td valign="top" width="250">
    <a href="detail.html"><?php the_title();?></a><br />
    <?php the_content();?></td>
    
    <?php if ($cnt == 1){ ?>
    <td><img src="/images/spacer.gif" width="10" height="1"></td>
    <?php } ?>
    
    <?php if ($cnt == 2){ ?>
    </tr>
    <?php } ?>
    
    <?php $cnt++; if($cnt>2) { $cnt=1; } ?>
    
    <?php endwhile; ?>
    
    <?php if ($cnt == 1){ ?>
    <td>&nbsp;</td>
    </tr>
    <?php } ?>
    </table>
    
    <?php endif; ?>

    とかでできるのではないでしょうか?
    部分的に間違ってる可能性あるので、雰囲気だけでも伝われば・・・

    トピック投稿者 fone

    (@fone)

    返事が遅くなって申し訳ありません。
    お教えいただいたものに少し手を加えたもので解決することができました。

    本当にありがとうございました。

2件の返信を表示中 - 1 - 2件目 (全2件中)
  • トピック「横並びに交互に並べた投稿のループ」には新たに返信することはできません。