忍者ブログ
29 March

[PR]

×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。

25 July

アドバンスドカスタムフィールド「Repeater Field」の表示を逆にする ワードプレス

<?php $rows = get_field('gallery');?>
<?php if($rows):?>
<?php $rows = array_reverse($rows);?>  // array_reverse();で配列の逆表示

(ループ内には入れないけどpage.phpに直接書きこみたいものはここへ)
<div>
<?php foreach($rows as $row) { // ループ開始
        // ループ内で使用する画像の指定
        $attachment_id = $row['gallery_img'];
        $image = wp_get_attachment_image_src( $attachment_id, 'gallery-custom-image' );
        $size = "custom-image"; // (thumbnail, medium, large, full or custom size)
        $imageF = wp_get_attachment_image_src( $attachment_id, 'full' );
        // url = $image[0];
        // width = $image[1];
        // height = $image[2];
?>

<table class="gallery_box"> <!--表示させたいカスタムフィールドの中身-->
  <tr>
    <th colspan="2"><a href="<?php echo $imageF[0]; ?>" rel="lightbox"><img src="<?php echo $image[0]; ?>" width="<?php echo $image[1]; ?>" height="<?php echo $image[2]; ?>"/></a>
</th>
  </tr>
  <tr>
    <th>題名</th>
    <td><?php echo $row['サブフィールド名']; ?></td>
  </tr>
</table>

 <?php  } ?>  // ループ終わり

</div>

(ループ内には入れないけどpage.phpに直接書きこみたいものはここへ)

<?php endif; ?><!--//<?php if($rows):?>-->


カスタムサイズの画像をサムネイルにして、クリックするとライトボックスでフル画像が開く。
Repeater Fieldは旧→新という順番で追加される。
ドラック&ドロップで順番は自由に入れ替えられるが、一斉に逆順序にしたいこともあるとおもう。
ギャラリーなど画像を並べたら、新しいものを上にしたいのではなかろうか?
そんなとき array_reverse(); を使って配列を逆にする。

http://www.advancedcustomfields.com/resources/field-types/repeater/
http://ja.forums.wordpress.org/topic/134901?replies=5#post-185382
PR