wordpress カスタムフィールド表示
the_field('ID');
the_field('explain');
echo get_field('ID');
echo get_field('explain');
$data = get_post_custom();
echo $data['ID'][0];
echo $data['explain'][0];
■画像表示参考
http://webcre-archive.com/2012/09/11/advanced-custom-fields-image/
■単画像
・function.php
function get_custom_img($fname, $fsize) {
$attachment_id = get_field($fname);
$image = wp_get_attachment_image_src( $attachment_id, $fsize );
$attachment = get_post( get_field($fname) );
$alt = get_post_meta($attachment->ID, '_wp_attachment_image_alt', true);
$image_title = $attachment->post_title;
$fimgobj = '<img class="img-responsive" src="'.$image[0].'" width="'.$image[1].'" height="'.$image[2].'" alt="'.$alt.'" title="'.$image_title.'">';
return $fimgobj;
・view
<?php echo get_custom_img('flyer','medium'); ?>
■複数画像
<?php for($i=1; $i<10; $i++): ?>
<?php
$id = post_custom("image$i");
if(wp_get_attachment_image($id) != ''):
?>
<?php echo wp_get_attachment_image($id,'thumbnail'); ?>
<?php endif; endfor; ?>
■画像のurlだけ取得
$image = wp_get_attachment_image_src(get_post_meta($post->ID, 'thumb', true), 'medium'); echo $image[0];
■カテゴリ・タクソノミー
<?php echo get_the_term_list(get_the_ID(), 'food_category' ); ?>