3
我有一個類別的頁面和我的wordpress網站上的單頁與自定義查詢。在主頁上工作的分頁是基於一個腳本在同一頁面上加載帖子的。WordPress的自定義查詢分頁和Ajax
問題是,分頁工作在單個頁面和類別只有<?php previous_posts_link('« Previous') ?>
該腳本不適用於單個頁面和類別。
下面的代碼:
<div class="main_container">
<div id="load_posts_container">
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args=array(
'post_type'=>'post',
'cat' => '-28' . $category_ID,
'posts_per_page' => 8,
'paged'=>$paged
);
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query($args);
if ($wp_query->have_posts()) : while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<!--ARTICLES MARKUP HERE-->
<?php endwhile; endif;
?>
<!--//load_posts_container-->
<
<div class="load_more_cont">
<p>Altri eventi <br/>
<span class="load_more_text"><?php next_posts_link('<img src="' . get_bloginfo('stylesheet_directory') . '/images/load-more-image.png" alt="Altri Eventi a Roma"/>', $wp_query->max_num_pages) ?></span>
</p>
</div>
<!--//load_more_cont-->
<?php $wp_query = null;
$wp_query = $temp;
wp_reset_query(); ?>
<script type="text/javascript">
// Ajax-fetching "Load more posts"
$('.load_more_cont a').live('click', function(e) {
e.preventDefault();
//$(this).addClass('loading').text('Loading...');
//$('.load_more_text a').html('Loading...');
$.ajax({
type: "GET",
url: $(this).attr('href') + '#main_container',
dataType: "html",
success: function(out) {
result = $(out).find('#load_posts_container .home_post_box');
nextlink = $(out).find('.load_more_cont a').attr('href');
//alert(nextlink);
//$('#boxes').append(result).masonry('appended', result);
$('#load_posts_container').append(result);
//$('.fetch a').removeClass('loading').text('Load more posts');
//$('.load_more_text a').html('Load More');
if (nextlink != undefined) {
$('.load_more_cont a').attr('href', nextlink);
} else {
$('.load_more_cont').remove();
$('#load_posts_container').append('<div class="clear"></div>');
// $('.load_more_cont').css('visibilty','hidden');
}
if (nextlink != undefined) {
$.get(nextlink, function(data) {
//alert(nextlink);
if($(data + ":contains('home_post_box')") != '') {
//alert('not found');
// $('.load_more_cont').remove();
$('#load_posts_container').append('<div class="clear"></div>');
}
});
}
}
});
});
</script>
任何想法? 感謝
你解決問題?你可以嘗試更換$ paged, $ paged =(get_query_var('paged'))? get_query_var('paged'):(get_query_var('page')?get_query_var('page'):1); – sven