I have a problem with getting a queued post ID or permalink from a loop and put it in some jQuery code, first of all, the code:
<div class="gallery">
<ul id="mycarousel">
<?php global $wp_query;
$args = array_merge( $wp_query->query, array( 'category__in' => array(get_query_var('cat')), 'posts_per_page' => 10));
query_posts( $args ); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<li><a class="gallerylink"><?php the_post_thumbnail()?></a></li>
<?php endwhile; endif; ?>
</ul>
</div>
<script type="text/javascript">
jQuery(document).ready(function($) {
$(".gallerylink").click(function () {
$("#loader").fadeIn(10);
$("#icontent").delay(800).fadeIn(200);
$("#mainFrame").attr("src", "http://www.wordpress.org");
});
$("#hide").click(function () {
$("#loader").css("display", "none");
$("#icontent").fadeOut(200);
setTimeout(function(){
$("#mainFrame").attr("src", "about:blank");
}, 250);
});
});
</script>
<div id ="loader"></div>
<div id="icontent">
<input type="button" id="hide" value="hide"></button>
<iframe src="" scrolling="no" frameborder="0" id="mainFrame" name="mainFrame"></iframe>
</div>
</div>
as you can see I queue posts using more detailed Wordpress query, it's inside category.php file. What I need is get a post permalink while clicking on link a.gallerylink and put in place of wordpress.org link inside of jQuery code. But what should I put in place of WP site link to make my site know which post link I chose to open an iFrame with currently clicked post?
thanks in advance!
PS, please don't ask why iFrame etc. It has to be done like that:)
Why not add the link to the href attr and then use jquery to grab it.
Just add fix your code to prevent the click from following the link:
$('.gallery').on('click', 'a', function(event) {
event.preventDefault();
var link = $(this).prop('href');
// your code here
});
Edit: a working example http://jsbin.com/EReMohU/1/edit
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.