gpt4 book ai didi

javascript - 宏伟的弹出窗口获得帖子父级的永久链接

转载 作者:行者123 更新时间:2023-12-03 00:33:53 25 4
gpt4 key购买 nike

我设置了自定义帖子类型“女性”。有 56 个帖子包含肖像和简介。然后,我设置了一个图库页面,从每个帖子中获取缩略图并将其显示在图库中。单击缩略图可使用放大弹出窗口打开包含全尺寸图像的模式。我遇到困难的地方是试图找出如何将图像标题中的永久链接添加到女性单页?在此代码片段中,永久链接链接回当前页面,而不是帖子父页面。我可以获得一些格式化 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') + ' &bull; <a href="<?php echo get_the_permalink(); ?>">Her Story</a>';
}
}
});

最佳答案

PHP部分

<a>标签,设置href到单个帖子永久链接,并设置 data-mfp-src到图像 URL ( $url ):

<li>
<a href="<?php the_permalink(); ?>" data-mfp-src="<?php echo $url; ?>" title="<?php echo $title; ?>">...</a>
</li>

JS部分

titleSrc回调,然后您可以使用 item.el.attr('href')获取单个帖子的固定链接:

titleSrc: function(item){
return item.el.attr('title') + ' &bull; <a href="' + item.el.attr('href') + '">Her Story</a>';
}

我输入了 demo在 CodePen 上,以及有关 data-mfp-src 的更多详细信息属性,请引用documentation .

关于javascript - 宏伟的弹出窗口获得帖子父级的永久链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53735235/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com