من یه کد نوشتم برای نمایش پست هام ، که با زدن روی هر عکس به صورت modal bootsrapt باز بشه
همه موارد درست کار می کنه فقط پست اول باز میشه وmodal بقیه پست ها باز نمیشه
قطعه کد اول :
<div class="row tm-gallery" >
<div id="tm-gallery-page-اول" class="tm-gallery-page">
<?php query_posts( 'category_name=painting&posts_per_page=50' ); ?><!-- posts per page by category_name -->
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<span class="new-wrapper">
<span><h1 class="tm-gallery-title1"><?php the_title(); ?></h1></span>
<a href="<?php echo the_permalink(); ?>" class="box col<?php echo rand(2,3); ?>"> <!-- randomize .col2 & .col3, creating the grid portfolio -->
<?php
$post_id = get_the_id();//make sure this getting the correct post id
//here change the direct thum to custom link like this
if ( has_post_thumbnail())
{
//here we can get the featured image of the post as a link
$feat_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); //make sure this will return the correct featured image url
//place the url in our custome html like this:
//in this we change the target as per the post id so each post have its own modal for show the content in the while loop.
?>
<a href="#post<?php echo $post_id; ?>" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#post<?php echo $post_id; ?>"><img class="img-fluid tm-gallery-imgg" src="<?php echo $feat_image;?>"></a>
<?php
}
// here the target is set as #post'current post id'
//here we starting the modal part
?>
</span>
<?php endwhile; endif; ?>
</div>
</div>
کد مربوط به MODAL:
<div class="modal fade" id="post<?php echo $post_id; ?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<!-- Here showing the title of the post -->
<h4 class="modal-title" id="myModalLabel"><?php the_title();?></h4>
</div>
<div class="modal-body" bgcolor="#cccccc">
<div class="modal-right">
<table style="width:100%">
<tbody>
<tr>
<td>
<?php the_content() // the content and img is adding here ?>
<img src="<?php echo $feat_image;?>" alt="Image" class="modal-left3">
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">بستن پنجره</button>
</div>
</div>
</div>
</div>
آیا مایل به ارسال نوتیفیکیشن و اخبار از طرف راکت هستید ؟