我目前正在为需要图片库的客户端制作一个Wordpress网站,单击图片将重定向到外部链接。
图库中的每个收藏都显示为帖子。因此,在每个帖子中,我都使用Wordpress的内置Gallery功能添加照片。
要为这些图像设置自定义URL,我使用了WP Gallery Custom Links插件,但是自定义链接并未分配给我想要的照片。
是否有任何方法可以获取由WP Gallery自定义链接插件设置的数据,或者是否可以通过仪表板为这些照片分配自定义URL?
在我的“ content-single.php”文件的源代码中,我正在使用“ foreach”循环并使用wp_prepare_attachment_for_js()函数提取附件中的照片,以输出附件数据:
<?php
if ( get_post_gallery() ) :
$gallery = get_post_gallery( get_the_ID(), false );
/* create an array of IDs from */
$gids = explode( ",", $gallery['ids'] );
/* Loop through all the image and output them one by one */
foreach ($gids as $id) {
/* pull all the available attachment data with the new function */
$attachment = wp_prepare_attachment_for_js($id);
$categories = get_the_category($attachment);
?>
<!--Image element loop begins -->
<a href="<?php echo $attachment['url']; ?>" id="av-masonry-1-item-284" data-av-masonry-item="284" class="av-masonry-entry isotope-item post-284 attachment type-attachment status-inherit hentry av-masonry-item-with-image <?php if($attachment['width']>=($attachment['height']*2)){ ?>av-landscape-img <?php }elseif($attachment['height']>=($attachment['width']*2)){ ?> av-portrait-img <?php } ?> lightbox-added av-masonry-item-loaded" title="A really beautiful town" itemprop="thumbnailUrl" style="position: absolute; left: 0%; top: 0px;">
<div class="av-inner-masonry-sizer"></div>
<figure class="av-inner-masonry main_color">
<div class="av-masonry-outerimage-container">
<div class="av-masonry-image-container" style="background-image: url(<?php echo $attachment['sizes']['full']['url']; ?>);">
<img src="<?php echo $attachment['sizes']['full']['url']; ?>" title="Salzburg by day" alt="">
</div>
</div>
<figcaption class="av-inner-masonry-content site-background">
<div class="av-inner-masonry-content-pos">
<div class="av-inner-masonry-content-pos-content">
<div class="avia-arrow"></div>
<h3 class="av-masonry-entry-title entry-title" itemprop="headline"><?php echo $attachment['title']; ?></h3>
<div class="av-masonry-entry-content entry-content" itemprop="text"><?php echo $attachment['caption']; ?></div>
</div>
</div>
</figcaption>
</figure>
</a>
<!-- Image element loop ends -->
<?php
}
endif;
?>
我尝试使用var_dump($ attachment)查找自定义URL的任何痕迹,但无济于事。
如果我能够掌握自定义URL,则将使用它替换循环中分配的URL:
<a href="<?php $attachment['url'] ?>" id="av-masonry-1-item-284" data-av-masonry-item="284" class="av-masonry-entry isotope-item post-284 attachment type-attachment status-inherit hentry av-masonry-item-with-image <?php if($attachment['width']>=($attachment['height']*2)){ ?>av-landscape-img <?php }elseif($attachment['height']>=($attachment['width']*2)){ ?> av-portrait-img <?php } ?> lightbox-added av-masonry-item-loaded" title="A really beautiful town" itemprop="thumbnailUrl" style="position: absolute; left: 0%; top: 0px;">