【发布时间】:2016-08-11 18:49:59
【问题描述】:
我使用自定义元框创建了 wordpress 库,并且我的代码提供了我想要的正确输出。 但试图以标准方式实现。
原码
$mytheme_gallery_one = get_post_meta( get_the_ID(), 'mytheme_image_one', true );
$mytheme_image_one_image = wp_get_attachment_image( $mytheme_gallery_one, 'large' );
$mytheme_image_one_url = wp_get_attachment_url( $mytheme_gallery_one );
$mytheme_gallery_two = get_post_meta( get_the_ID(), 'mytheme_image_two', true );
$mytheme_image_two_image = wp_get_attachment_image( $mytheme_gallery_two, 'large' );
$mytheme_image_two_url = wp_get_attachment_url( $mytheme_gallery_two );
$mytheme_gallery_three = get_post_meta( get_the_ID(), 'mytheme_image_three', true );
$mytheme_image_three_image = wp_get_attachment_image( $mytheme_gallery_three, 'large' );
$mytheme_image_three_url = wp_get_attachment_url( $mytheme_gallery_three );
?>
<figure class="fit-vid ed-youtube">
<a href="<?php echo $mytheme_image_one_url; ?>" ><?php echo $mytheme_image_one_image; ?></a>
<a href="<?php echo $mytheme_image_two_url; ?>" ><?php echo $mytheme_image_two_image; ?></a>
<a href="<?php echo $mytheme_image_two_url; ?>" ><?php echo $mytheme_image_two_image; ?></a>
</fiture>
我正在尝试使用 foreach 使其简短:
foreach {
my_theme_gallery;
my_theme_image;
my_theme_url
<figure class="fit-vid ed-youtube">
<a href="<?php echo $mytheme_image_one_url; ?>" ><?php echo $mytheme_image_one_image; ?></a>
</fiture>
}
并且需要输出多张上传的图片。
【问题讨论】:
-
@MarcB 他发布了他的原始代码,他发布了他的尝试(在 foreach 循环中)。虽然不是一个好问题,但我认为这有点粗鲁。
标签: php wordpress gallery meta