繁体   English   中英

Ge在category.php中的Wordpress中的帖子ID

[英]Ge the post ID in Wordpress in category.php

我在从循环中获取排队的帖子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>

如您所见,我使用更详细的Wordpress查询对帖子进行排队,它位于category.php文件中。 我需要的是在单击链接a.gallerylink的同时获得一个帖子永久链接,并在jQuery代码中替换wordpress.org链接。 但是,我应该用什么代替WP网站链接以使我的网站知道我选择使用当前单击的帖子打开iFrame的哪个链接?

提前致谢!

PS,请不要问为什么要使用iFrame等。必须这样做:)

为什么不将链接添加到href属性,然后使用jquery来获取它。

只需添加修复代码,以防止点击以下链接:

$('.gallery').on('click', 'a', function(event) {
  event.preventDefault();
  var link = $(this).prop('href');
  // your code here
});

编辑:一个工作示例http://jsbin.com/EReMohU/1/edit

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM