如何获得"attachement_id=“
就像这里;

我希望有人能给我一个答案。我想将这个id绑定到jquery选择器以获得全屏图像。
发布于 2014-11-26 13:53:20
就这样修好了;
foreach ($metas as $metakey) {
$image_id++;
echo "<div class='image' id='img_$image_id'>";以及jquery选择器;
$('#img\\_<?php echo $image_id ?>').on('click', function () {这样,我点击的每一个图像,实际上就是那个图像。所以我得到了这个
$full_image = wp_get_attachment_image_src($metakey['image'], 'full');
<script>
$('#img\\_<?php echo $image_id ?>').on('click', function () {
alert('<?php echo $full_image[0] ?>');
});
</script>这会使我点击的每一张图片都得到正确的url。
不过还是谢谢。
发布于 2014-11-26 13:14:33
这有点复杂,因为所有附件都链接到给定的帖子。
示例:用于显示附在某个页面上的所有图像和标题,并将其显示为列表,您可以使用以下方法:
<?php if ( have_posts() ) : while ( have_posts() ) : the_post();
$args = array(
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' => null,
'post_parent' => $post->ID
);
$attachments = get_posts( $args );
if ( $attachments ) {
foreach ( $attachments as $attachment ) {
echo wp_get_attachment_image( $attachment->ID, 'full' );
echo '<br/>';
echo apply_filters( 'the_title', $attachment->post_title );
}
}
endwhile; endif; ?>发布于 2014-11-26 13:15:00
你要找的是:
$attachment->ID看一看函数wp_get_attachment_image
参考资料:Wordpress附件
您必须获得$post->ID才能使其工作。
参考资料:https://core.trac.wordpress.org/browser/tags/4.0.1/src/wp-includes/link-template.php#L392
https://stackoverflow.com/questions/27149730
复制相似问题