添加指向图库图像的自定义链接

时间:2019-10-30 作者:sialfa

我需要将一些画廊图片链接到外部网站。经过一些研究,我无法找到一个不使用插件的解决方案。这在没有插件的wp中是可能的吗?

NB: I don\'t want to use a plugin, my client don\'t want to have plugins installed!

这是我的代码:

$args = array(
\'post_type\' => \'post\',
\'name\' => \'partners\'
);
$logo_img = new WP_Query( $args );
?>
<div class="container-fluid" id="">
  <div class="row" style="margin-top:1em;margin-bottom:1em;">
<?php if( $logo_img->have_posts() ): while( $logo_img->have_posts() ): $logo_img->the_post();
$logo_gallery = get_post_gallery_images( $post->ID );
if( $logo_gallery ): ?>
  <div class="col-sm-12 col-md-12 col-lg-12 text-center">
<?php foreach($logo_gallery as $logo ): ?>
    <img class="img-fluid" src="<?php echo $logo; ?>" alt="" width="60" id="partner-logo" style="margin:0 .5em 0 .5em;"/>
<?php endforeach; ?>
  </div>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; wp_reset_postdata(); ?>
  </div>
</div>

1 个回复
SO网友:Girish

这正是您需要的插件-https://wordpress.org/plugins/gallery-custom-links/

无需代码自定义。

对于固定图像链接(http://www.example.com):

$args = array(
\'post_type\' => \'post\',
\'name\' => \'partners\'
);
$logo_img = new WP_Query( $args );
?>
<div class="container-fluid" id="">
  <div class="row" style="margin-top:1em;margin-bottom:1em;">
<?php if( $logo_img->have_posts() ): while( $logo_img->have_posts() ): $logo_img->the_post();
$logo_gallery = get_post_gallery_images( $post->ID );
if( $logo_gallery ): ?>
  <div class="col-sm-12 col-md-12 col-lg-12 text-center">
<?php foreach($logo_gallery as $logo ): ?>
    <a href="http://www.example.com">
    <img class="img-fluid" src="<?php echo $logo; ?>" alt="" width="60" id="partner-logo" style="margin:0 .5em 0 .5em;"/>
    </a>
<?php endforeach; ?>
  </div>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; wp_reset_postdata(); ?>
  </div>
</div>