admin管理员组文章数量:1130349
I am pulling images from an ACF gallery that resides on another page. What I intend to do with this is to have these images displaying full screen on my home page on a popup every time the page loads. However, when a website user lands on the home page a random image should popup but only once, so if he navigates to other pages and then back to the home page again these images should not popup again and when the user revisits the website again he should get a different image from his previous visit. This is the code I have so far:
$masonry_photos_year = get_field('masonry_gallery_of_the_year', 600/*1168*/); ?>
<?php if( $masonry_photos_year ) :
$masonry_photos_year = array_unique($masonry_photos_year);
$masonry_photos_year = array_rand($masonry_photos_year);
?>
<div id="full-image" class="white-popup mfp-with-anim mfp-hide">
<?php
foreach ( $masonry_photos_year as $masonry_photo_year ) :
?>
<div class="full-image-info-wrapper">
<div class="container-fluid">
<div class="col-sm-6">
<?php if( $masonry_photo_year['description'] ) : ?>
<div class="photo-year">
<h3><?php echo esc_html( $masonry_photo_year['description']); ?></h3>
</div>
<?php endif; ?>
</div>
<div class="col-sm-6">
<?php if( $masonry_photo_year['caption'] ) : ?>
<div class="photo-name">
<h3><?php echo esc_html( $masonry_photo_year['caption']); ?></h3>
</div>
<?php endif; ?>
</div>
</div>
</div>
<img src="<?php echo $masonry_photo_year['sizes']['post-xlarge'] ?>" class="img-responsive" alt="<?php echo $masonry_photo_year['alt']; ?>">
<?php endforeach; ?>
</div>
<?php endif; ?>
Images are displaying on the popup as expected but I am stuck on how to implement the random bit and to ensure that the same image does not display in succession on a next user visit. How could I achieve this?
I am pulling images from an ACF gallery that resides on another page. What I intend to do with this is to have these images displaying full screen on my home page on a popup every time the page loads. However, when a website user lands on the home page a random image should popup but only once, so if he navigates to other pages and then back to the home page again these images should not popup again and when the user revisits the website again he should get a different image from his previous visit. This is the code I have so far:
$masonry_photos_year = get_field('masonry_gallery_of_the_year', 600/*1168*/); ?>
<?php if( $masonry_photos_year ) :
$masonry_photos_year = array_unique($masonry_photos_year);
$masonry_photos_year = array_rand($masonry_photos_year);
?>
<div id="full-image" class="white-popup mfp-with-anim mfp-hide">
<?php
foreach ( $masonry_photos_year as $masonry_photo_year ) :
?>
<div class="full-image-info-wrapper">
<div class="container-fluid">
<div class="col-sm-6">
<?php if( $masonry_photo_year['description'] ) : ?>
<div class="photo-year">
<h3><?php echo esc_html( $masonry_photo_year['description']); ?></h3>
</div>
<?php endif; ?>
</div>
<div class="col-sm-6">
<?php if( $masonry_photo_year['caption'] ) : ?>
<div class="photo-name">
<h3><?php echo esc_html( $masonry_photo_year['caption']); ?></h3>
</div>
<?php endif; ?>
</div>
</div>
</div>
<img src="<?php echo $masonry_photo_year['sizes']['post-xlarge'] ?>" class="img-responsive" alt="<?php echo $masonry_photo_year['alt']; ?>">
<?php endforeach; ?>
</div>
<?php endif; ?>
Images are displaying on the popup as expected but I am stuck on how to implement the random bit and to ensure that the same image does not display in succession on a next user visit. How could I achieve this?
Share Improve this question edited May 30, 2017 at 9:30 Paulo asked May 30, 2017 at 9:18 PauloPaulo 213 bronze badges1 Answer
Reset to default 0move $masonry_photos_year = array_rand($masonry_photos_year); inside foreach
I am pulling images from an ACF gallery that resides on another page. What I intend to do with this is to have these images displaying full screen on my home page on a popup every time the page loads. However, when a website user lands on the home page a random image should popup but only once, so if he navigates to other pages and then back to the home page again these images should not popup again and when the user revisits the website again he should get a different image from his previous visit. This is the code I have so far:
$masonry_photos_year = get_field('masonry_gallery_of_the_year', 600/*1168*/); ?>
<?php if( $masonry_photos_year ) :
$masonry_photos_year = array_unique($masonry_photos_year);
$masonry_photos_year = array_rand($masonry_photos_year);
?>
<div id="full-image" class="white-popup mfp-with-anim mfp-hide">
<?php
foreach ( $masonry_photos_year as $masonry_photo_year ) :
?>
<div class="full-image-info-wrapper">
<div class="container-fluid">
<div class="col-sm-6">
<?php if( $masonry_photo_year['description'] ) : ?>
<div class="photo-year">
<h3><?php echo esc_html( $masonry_photo_year['description']); ?></h3>
</div>
<?php endif; ?>
</div>
<div class="col-sm-6">
<?php if( $masonry_photo_year['caption'] ) : ?>
<div class="photo-name">
<h3><?php echo esc_html( $masonry_photo_year['caption']); ?></h3>
</div>
<?php endif; ?>
</div>
</div>
</div>
<img src="<?php echo $masonry_photo_year['sizes']['post-xlarge'] ?>" class="img-responsive" alt="<?php echo $masonry_photo_year['alt']; ?>">
<?php endforeach; ?>
</div>
<?php endif; ?>
Images are displaying on the popup as expected but I am stuck on how to implement the random bit and to ensure that the same image does not display in succession on a next user visit. How could I achieve this?
I am pulling images from an ACF gallery that resides on another page. What I intend to do with this is to have these images displaying full screen on my home page on a popup every time the page loads. However, when a website user lands on the home page a random image should popup but only once, so if he navigates to other pages and then back to the home page again these images should not popup again and when the user revisits the website again he should get a different image from his previous visit. This is the code I have so far:
$masonry_photos_year = get_field('masonry_gallery_of_the_year', 600/*1168*/); ?>
<?php if( $masonry_photos_year ) :
$masonry_photos_year = array_unique($masonry_photos_year);
$masonry_photos_year = array_rand($masonry_photos_year);
?>
<div id="full-image" class="white-popup mfp-with-anim mfp-hide">
<?php
foreach ( $masonry_photos_year as $masonry_photo_year ) :
?>
<div class="full-image-info-wrapper">
<div class="container-fluid">
<div class="col-sm-6">
<?php if( $masonry_photo_year['description'] ) : ?>
<div class="photo-year">
<h3><?php echo esc_html( $masonry_photo_year['description']); ?></h3>
</div>
<?php endif; ?>
</div>
<div class="col-sm-6">
<?php if( $masonry_photo_year['caption'] ) : ?>
<div class="photo-name">
<h3><?php echo esc_html( $masonry_photo_year['caption']); ?></h3>
</div>
<?php endif; ?>
</div>
</div>
</div>
<img src="<?php echo $masonry_photo_year['sizes']['post-xlarge'] ?>" class="img-responsive" alt="<?php echo $masonry_photo_year['alt']; ?>">
<?php endforeach; ?>
</div>
<?php endif; ?>
Images are displaying on the popup as expected but I am stuck on how to implement the random bit and to ensure that the same image does not display in succession on a next user visit. How could I achieve this?
Share Improve this question edited May 30, 2017 at 9:30 Paulo asked May 30, 2017 at 9:18 PauloPaulo 213 bronze badges1 Answer
Reset to default 0move $masonry_photos_year = array_rand($masonry_photos_year); inside foreach
本文标签: advanced custom fieldsRandom popup image per user with no repeat
版权声明:本文标题:advanced custom fields - Random popup image per user with no repeat 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749164277a2325910.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论