【发布时间】:2018-12-12 02:29:03
【问题描述】:
我设置了一个自定义帖子类型“女性”。有 56 个帖子,包括肖像和简历。然后,我设置了一个图库页面,该页面从每个帖子中获取缩略图并将其显示在图库中。单击缩略图会使用 Magnific Popup 打开带有全尺寸图像的模式。我陷入困境的地方是试图弄清楚如何将图像标题中的永久链接添加到女性单页?在这个 sn-p 中,永久链接链接回当前页面而不是帖子父级。我可以得到一些格式化 titleSrc 的方向吗?谢谢。
<ul class="popup-gallery scroll-effect">
<?php
$args = array('post_type' => 'women','orderby' => 'title', 'order' => 'ASC', 'posts_per_page' => 100);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
$image = get_field('portrait');
$post_id = get_field('url', false, false);
if( !empty($image) ):
$url = $image['url'];
$title = $image['title'];
$alt = $image['alt'];
$size = 'medium';
$thumb = $image['sizes'][ $size ];
$width = $image['sizes'][ $size . '-width' ];
$height = $image['sizes'][ $size . '-height' ];
?>
<li>
<a href="<?php echo $url; ?>" title="<?php echo $title; ?>">
<img class="icon" src="<?php echo get_template_directory_uri(); ?>/i/icon-image-expand.png">
<img src="<?php echo $thumb; ?>" alt="<?php echo $alt; ?>" width="<?php echo $width; ?>" height="<?php echo $height; ?>" />
</a>
</li>
<?php endif; ?>
<?php endwhile; wp_reset_query();?>
</ul>
$('.popup-gallery').magnificPopup({
delegate: 'a',
type: 'image',
tLoading: 'Loading image #%curr%...',
mainClass: 'mfp-img-mobile',
gallery: {
enabled: true,
navigateByImgClick: true,
preload: [0,1]
},
image: {
tError: '<a href="%url%">The image #%curr%</a> could not be loaded.',
titleSrc: function(item) {
return item.el.attr('title') + ' • <a href="<?php echo get_the_permalink(); ?>">Her Story</a>';
}
}
});
【问题讨论】:
-
呈现画廊项目 HTML 的 PHP 代码在哪里?
-
谢谢。我刚刚将 PHP 添加到 OP 中。
-
我刚刚发布了一个答案。让我知道。 :)
标签: javascript php wordpress custom-post-type magnific-popup