我需要点击加载更多按钮或替代方法来获取WordPress帖子。我已经按照教程Here
进行了操作<?php
/*
Template Name: Additional Posts
*/
$offset = htmlspecialchars(trim($_GET['offset']));
if ($offset == '') {
$offset = 5;
}
$args = 'post_type=event&posts_per_page=3&offset=$offset';
$my_query = new WP_Query($args);
if ( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post();
$event_id = get_post_meta( get_the_ID(), '_event_id', true );
$location_id = get_post_meta( get_the_ID(), '_location_id', true );
$custom_fields = get_post_custom(get_the_ID());
global $wpdb;
$em_states = $wpdb->get_results("SELECT *from ".EM_LOCATIONS_TABLE." WHERE location_id = '$location_id' ");
$em_ticket_price = $wpdb->get_results("SELECT *from ".EM_TICKETS_TABLE." WHERE event_id = '$event_id' ");
?>
<div class="filter-box clearfix post">
<div class="row-fluid">
<div class="span4"><?php echo get_the_post_thumbnail(get_the_ID(), array(269,168) ); ?> </div>
<div class="span5">
<h5><span class="switch_rest"><?php echo $em_states[0]->location_town;?> -</span> <?php the_title(); ?></h5>
<ul class="clearfix">
<li><i class="icon-time pad-rht"></i><?php $star_time = get_post_meta( get_the_ID(), '_start_ts', true ); echo date('g:i:s a ',$star_time);?>-<?php $end_time = get_post_meta( get_the_ID(), '_end_ts', true ); echo date('g:i:s a ',$end_time); ?> </li>
<li> <i class="icon-folder-open pad-rht"></i><?php
$terms = get_the_terms(get_the_ID(), 'event-categories' );
if ($terms && ! is_wp_error($terms)) :
$term_slugs_arr = array();
foreach ($terms as $term) {
$term_slugs_arr[] = $term->name;
}
$terms_slug_str = join( " | ", $term_slugs_arr);
endif;
echo $terms_slug_str;?> </li>
<li><i class="icon-user pad-rht"></i><?php echo $custom_fields['wpcf-from'][0]."-".$custom_fields['wpcf-to'][0]; ?> </li>
</ul>
</div>
<div class="span3">
<div class="price-box clearfix">
<h4>Price Range</h4>
<ul class="inline clearfix">
<!-- <li>From</li>-->
<li><?php echo $em_ticket_price[0]->ticket_price; ?>€</li>
<br />
<!-- <li>To </li>
<li>100€</li>-->
</ul>
</div>
</div>
</div>
</div>
</div>
<?php endwhile; } ?>
我的jquery是:
<script type="text/javascript">
var $j = jQuery.noConflict();
$j(function(){
var offset = 0;
// $j("#postContainer").load("<?php echo get_site_url(); ?>/additional-posts/?offset="+offset);
$j("#another").click(function(){
offset = offset+3;
$j("#postContainer")
// .slideUp()
.load("<?php echo get_site_url(); ?>/additional-posts/?offset="+offset, function() {
$j(this).slideDown();
});
return false;
});
});
</script>
它正在工作但是当我点击获取更多链接时,我再次从原始循环获得相同的帖子。我知道缺少分页查询还缺少什么?