Javascript 在category.php中的Wordpress中设置帖子ID
我在从循环中获取排队的post ID或permalink并将其放入一些jQuery代码时遇到问题,首先,代码:Javascript 在category.php中的Wordpress中设置帖子ID,javascript,php,jquery,wordpress,iframe,Javascript,Php,Jquery,Wordpress,Iframe,我在从循环中获取排队的post ID或permalink并将其放入一些jQuery代码时遇到问题,首先,代码: <div class="gallery"> <ul id="mycarousel"> <?php global $wp_query; $args = array_merge( $wp_query->query, array( 'category__in' => array(get_query_var('cat')), '
<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>
jQuery(文档).ready(函数($){
$(“.gallerylink”)。单击(函数(){
$(“#加载器”).fadeIn(10);
美元(“#icontent”)。延迟(800)。fadeIn(200);
$(“#大型机”).attr(“src”http://www.wordpress.org");
});
$(“#隐藏”)。单击(函数(){
$(“#加载程序”).css(“显示”、“无”);
美元(“#i内容”)。淡出(200);
setTimeout(函数(){
$(“#大型机”).attr(“src”,“about:blank”);
}, 250);
});
});
正如您所看到的,我使用更详细的Wordpress查询对帖子进行排队,它位于category.php文件中。我需要的是在点击链接a.gallerylink的同时获得一个post permalink,并在jQuery代码中放置wordpress.org链接。但是我应该用什么来代替WP站点链接,让我的站点知道我选择了哪个帖子链接来打开当前点击的帖子的iFrame
提前谢谢
PS,请不要问为什么iFrame等。它必须这样做:)为什么不将链接添加到href attr,然后使用jquery获取它 只需添加修复代码,即可防止单击链接:
$('.gallery').on('click', 'a', function(event) {
event.preventDefault();
var link = $(this).prop('href');
// your code here
});
编辑:一个工作示例是否在末尾有一个额外的
?