admin管理员组文章数量:1333210
I'm trying to replicate that codepen but using php wordpress. Basically I want my blogpost images displaying in another div and it changes every time you select another menu.
Thanks for the help. Here is my code:
<?php
$images = get_field('gallery');
if( $images ): ?>
<ul>
<?php foreach( $images as $image ): ?>
<li>
<img src="<?php echo esc_url($image['sizes']['thumbnail']); ?>" alt="<?php echo esc_attr($image['alt']); ?>" />
<p><?php echo esc_html($image['caption']); ?></p>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
I have noticed that $images = get_field('gallery');
stores the image of the latests post before its called. So I guess it has something to do with that. Now I wish I could just get all the images somewhere and apply them a data id corresponding to my articles. That is why I have a $counter = -1;
.
Here is the complete code:
<div class="four">
<?php
$counter = -1;
// the query
$all_posts = new WP_Query( array( 'post_type' => 'post', 'post_status' => 'publish', 'posts_per_page' => -1 ) );
if ( $all_posts->have_posts() ) :
?>
<ul>
<?php while ( $all_posts->have_posts() ) : $all_posts->the_post(); $counter++ ?>
<li class='sub-menu'> <a href='#' class="exposition" data-id="divId<?php echo $counter; ?>"><?php the_title(); ?></a> <ul>
<li><?php the_content(); ?>
</li>
</ul>
</li>
<?php endwhile; ?>
</ul>
<?php else : ?>
<?php endif; ?>
</div>
<div class="five">
<?php
$images = get_field('gallery');
if( $images ): ?>
<ul> <div class="slide-photos" id="divId<?php echo $counter; ?>" data-id="divId<?php echo $counter; ?>">
<?php foreach( $images as $image ): ?>
<li>
<div class="photos-ind"><img id="divId<?php echo $counter; ?>" class="slide-photos" src="<?php echo esc_url($image['sizes']['thumbnail']); ?>" data-id="divId<?php echo $counter; ?>"/></div>
</li>
<?php endforeach; ?>
</div>
</ul>
<?php endif; ?>
</div>
</div>
All it does from now, is just displaying the latests post's images correctly, what I would like is that its able to detect which post i'm clicking and display the image corresponding.
本文标签: pluginsDisplaying all the images from all of my articles
版权声明:本文标题:plugins - Displaying all the images from all of my articles 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742244728a2439057.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论