我编写了一个循环,显示了附加到特定帖子类型的每个帖子上的所有图像。帖子类型称为“atls\\U事件”,我为每个帖子附加的图像输出一个称为“视频拇指”的图像大小。这些我都做得很好。您可以在此处看到代码:
<?php
$query = new WP_Query(
array(
\'post_type\' => \'atls_event\',
\'posts_per_page\' => -1,
\'fields\' => \'ids\'
)
);
$image_query = new WP_Query(
array(
\'post_type\' => \'attachment\',
\'post_status\' => \'inherit\',
\'post_mime_type\' => \'image\',
\'posts_per_page\' => -1,
\'post_parent__in\' => $query->posts,
\'order\' => \'DESC\'
)
);
if( $image_query->have_posts() ){
while( $image_query->have_posts() ) {
$image_query->the_post();?>
<div class="m-1of2 t-1of3 d-1of6 cf">
<?php $imgurl = wp_get_attachment_image($image->ID, \'video-thumb\');
echo \'<a href="\';
echo get_permalink(); //this is where I try to link to the post
echo \'">\';
echo $imgurl;
echo \'</a>\';?>
</div>
<?php } } ?>
我要做的是将每个缩略图链接到图像所附加到的帖子。我正试图用以下代码来实现这一点:
<?php $imgurl = wp_get_attachment_image($image->ID, \'video-thumb\');
echo \'<a href="\';
echo get_permalink(); //this is where I try to link to the post
echo \'">\';
echo $imgurl;
echo \'</a>\';?>
但是,这会将图像链接到特定图像的附件页。如何将图像链接到帖子本身?