<div class="home-thumbs bottom-thumbs">
<?php $home_query_bottom = new WP_Query("cat=&showposts=20&offset=5"); $b = 0; ?>
<ul class="thumbs">
<?php while ($home_query_bottom->have_posts()) : $home_query_bottom->the_post();
$do_not_duplicate = $post->ID; $b++; ?>
<li class="post-<?php the_ID(); ?> thumb"><?php get_the_image(array('custom_key' => array('thumbnail'), 'default_size' => 'thumbnail', 'width' => '160', 'height' => '160')); ?></li>
<?php endwhile; wp_reset_query(); $b = 0; ?>
</ul>
</div>
<div id="output"></div>
<script type="text/javascript">
$('.go-right').click(function(){
$.ajax({
type: "POST",
url: "process_thumbs.php",
data: "showposts=25",
success: function(html){
$("#output").html(html);
}
});
});
</script>
// process_thumbs.php
<body>
<?php $numposts = $_POST['showposts']; ?>
<div><?php echo "this is the amount of posts to be shown: $numposts"; ?></div>
</body>
看起来像一个简单的ajax调用。 .go-right确实存在,它只是在另一个文件中,我测试了点击正在执行。这个Ajax调用基本上不起作用。也许有人可以确定我的代码是否错误。我的jquery ajax不能在我的WordPress网站上工作
理想我想采取WP-查询循环和使用Ajax与不同showposts再次运行该循环,如果有人点击偏移。
感谢。我检查了chrome的开发人员工具,它说我的process_thumbs.php 404错误。说www.url.com/process_thumbs.php,这不是网址。我想在wordpress中你需要绝对路径? – Adam 2011-01-09 17:36:11