<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>
Seems like a simple ajax call. .go-right does exist it’s just in anoher file and I’ve tested that the click is executing. This ajax call is basically not working. Maybe someone could identify if my code is wrong.
Ideally I want to take that wp-Query loop and use ajax to run that loop again with different showposts and offset if someone clicks.
Make sure that
.go-rightis before the jQuery code OR (better) wrap your jquery inor similar, to make sure that the handler is really attached to your
.go-rightelementDo not output
<body>tags in yourprocess_thumbs.php, maybe this is confusing jQuery.Check Firebug console/net tabs, to make sure that the request is really being sent.
Add an
errorcallback to your.ajax, to make sure that your ajax call really gets executed.Yeah, use absolute urls but with a wordpress helper function:
This way, all of your URLs will be relative to WordPress root url.