[wordpress]カスタムフィールドに登録した画像を呼び出す。
関数リファレンス/get post meta – WordPress Codex 日本語版
カスタムフィールドにkeyをimageとして登録した画像を呼び出す。
Function Reference/wp get attachment image « WordPress Codex
呼び出せるのはIDなので添付されてる画像を呼び出す。
サイズやアトリビュートを指定可能。
1 2 3 4 5 6 7 8 9 | wp_get_attachment_image( $attachment_id, $size, $icon, $attr ); $size = thumbnail, medium, large or full $default_attr = array( 'src' => $src, 'class' => "attachment-$size", 'alt' => trim(strip_tags( get_post_meta($attachment_id, '_wp_attachment_image_alt', true) )), 'title' => trim(strip_tags( $attachment->post_title )), ); |
サンプル(ループ内で呼び出す)
1 | <?php echo wp_get_attachment_image(get_post_meta($post->ID, thumb, true),full);?> |
No related posts.



