最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Javascript Tab Gallery with Advanced Custom Fields

programmeradmin2浏览0评论

I'm using Advanced Custom Fields on my site, i want to display pictures for my gallery field on a presentable, elegant way. So i was thinking on do something like this:

.asp

My main issue is that i don't know how to put the php variables on the javascript code. Can you help?

The same css and the same script from the w3schools example, and this is my code:

<?php 

$images = get_field('extra_photos');

if( $images ): ?>
<div class="row2">
<div class="column2" >
<?php foreach( $images as $image ): ?>
    <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?> " onclick="myFunction(this);"/>
<?php endforeach; ?>    
</div>
</div>
<!-- The expanding image container -->
<div class="container2">
  <!-- Close the image -->
  <span onclick="this.parentElement.style.display='none'" class="closebtn">&times;</span>

  <!-- Expanded image -->
  <img id="expandedImg" style="width:100%">

  <!-- Image text  --> 
  <div id="imgtext"></div>
</div>


<?php endif; ?>

/

I don't know why it displays the pictures like one by one line, i want to display them all next to each other. How can i do it?

I'm using Advanced Custom Fields on my site, i want to display pictures for my gallery field on a presentable, elegant way. So i was thinking on do something like this:

https://www.w3schools/howto/howto_js_tab_img_gallery.asp

My main issue is that i don't know how to put the php variables on the javascript code. Can you help?

The same css and the same script from the w3schools example, and this is my code:

<?php 

$images = get_field('extra_photos');

if( $images ): ?>
<div class="row2">
<div class="column2" >
<?php foreach( $images as $image ): ?>
    <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?> " onclick="myFunction(this);"/>
<?php endforeach; ?>    
</div>
</div>
<!-- The expanding image container -->
<div class="container2">
  <!-- Close the image -->
  <span onclick="this.parentElement.style.display='none'" class="closebtn">&times;</span>

  <!-- Expanded image -->
  <img id="expandedImg" style="width:100%">

  <!-- Image text  --> 
  <div id="imgtext"></div>
</div>


<?php endif; ?>

http://electives-abroad/mnazi-mmoja-in-zanzibar-tanzania/

I don't know why it displays the pictures like one by one line, i want to display them all next to each other. How can i do it?

Share Improve this question edited May 6, 2019 at 3:06 Draws Ren Gundam asked May 6, 2019 at 2:14 Draws Ren GundamDraws Ren Gundam 251 gold badge2 silver badges6 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Fixed it!

This is the resulting code:

<?php 

$images = get_field('extra_photos');

if( $images ): ?>
<div class="row2">

<?php foreach( $images as $image ): ?>
    <div class="column2" >
    <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?> " onclick="myFunction(this);"/>
    </div>
<?php endforeach; ?>    

</div>
<!-- The expanding image container -->
<div class="container2">
  <!-- Close the image -->
  <span onclick="this.parentElement.style.display='none'" class="closebtn">&times;</span>

  <!-- Expanded image -->
  <img id="expandedImg" style="width:100%">

  <!-- Image text  --> 
  <div id="imgtext"></div>
</div>


<?php endif; ?>
发布评论

评论列表(0)

  1. 暂无评论