サポート » プラグイン » Custom Field Template のグループ化したものを更にグループ化

  • aztanino

    (@aztanino)


    はじめまして。
    Custom Field Templateのグループ化+multipleの複製機能を使用し、
    商品リストページのようなものを作りたいと思っています。

    [field0]
    type = fieldset_open
    legend = 価格表の作成
    multipul = true
    multipleButton = true
    
    [small_title]
    type = text
    size = 35
    label = タイトル
    blank = true
    
    [field1]
    type = fieldset_open
    legend = 価格表の作成
    multipul = true
    multipleButton = true
    
    [item_img]
    type = file
    mediaPicker = true
    mediaRemove = true
    label = 商品画像
    blank = true
    
    [item_name]
    type = text
    size = 35
    label = 商品名
    blank = true
    
    [item_price]
    type = text
    size = 35
    label = 価格
    blank = true
    
    [item_setsumei]
    type = textarea
    rows = 4
    cols = 40
    label = 商品説明
    blank = true
    
    [field1]
    type = fieldset_close
    
    [field0]
    type = fieldset_close

    上記のように商品をグループ化したものの上にタイトルをつけて更にグループ化をしてみました。
    管理画面上で問題なく動くのですが、PHPの知識に乏しいため表示をどのようにすれば良いのかわかりません。
    現状は、商品だけをグル―プ化させて下記のように書いています。
    ここから、どのようにいじれば良いのかお答えいただければ幸いです。
    よろしくお願い致します。

    <?php
    global $wpdb;
    $query = "SELECT meta_id,post_id,meta_key,meta_value FROM $wpdb->postmeta WHERE post_id = $post->ID ORDER BY meta_id ASC";
    $cf = $wpdb->get_results($query, ARRAY_A);
    
    $item_img = array();
    $item_name = array();
    $item_price = array();
    $item_setsumei = array();
    
    foreach( $cf as $row ){
    		if( $row['meta_key'] == "item_img" ){
    				array_push( $item_img, $row['meta_value'] );
    		}
    		if( $row['meta_key'] == "item_name" ){
    				array_push( $item_name, $row['meta_value'] );
    		}
    		if( $row['meta_key'] == "item_price" ){
    				array_push( $item_price, $row['meta_value'] );
    		}
    		if( $row['meta_key'] == "item_setsumei" ){
    				array_push( $item_setsumei, $row['meta_value'] );
    		}
    }
    
    $length = count( $item_name );
    
    for( $i = 0; $i < $length; $i ++ ){
    	//画像取得
    	$gazou_sp = wp_get_attachment_image_src($item_img[$i],'full' );
     ?>
     <?php if($item_name[$i] !='') { ?>
    
    		<table>
    			<tr>
    				<th rowspan="2" style="width:250px;"><img src="<?php echo $gazou_sp[0]; ?>" alt="<?php the_title(); ?>" /></th>
    				<td style="width:220px; vertical-align:middle;"><?php echo wpautop($item_name[$i]); ?></td>
    				<td style="vertical-align:middle;"><?php echo wpautop($item_price[$i]); ?></td>
    			</tr>
    			<tr>
    				<td colspan="2"><?php echo wpautop($item_setsumei[$i]); ?></td>
    			</tr>
    		</table>
    
    <?php }}
    ?>
  • トピック「Custom Field Template のグループ化したものを更にグループ化」には新たに返信することはできません。