[英]Ge the post ID in Wordpress in category.php
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: 我在从循环中获取排队的帖子ID或永久链接并将其放入一些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')), '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. 如您所见,我使用更详细的Wordpress查询对帖子进行排队,它位于category.php文件中。 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.
我需要的是在单击链接a.gallerylink的同时获得一个帖子永久链接,并在jQuery代码中替换wordpress.org链接。 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?
但是,我应该用什么代替WP网站链接以使我的网站知道我选择使用当前单击的帖子打开iFrame的哪个链接?
thanks in advance! 提前致谢!
PS, please don't ask why iFrame etc. It has to be done like that:) PS,请不要问为什么要使用iFrame等。必须这样做:)
Why not add the link to the href attr and then use jquery to grab it. 为什么不将链接添加到href属性,然后使用jquery来获取它。
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 编辑:一个工作示例http://jsbin.com/EReMohU/1/edit
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.