My Wordpress website has custom category and single pages with a unique query. The pagination is set up to load posts on the same page, which works fine on the homepage.
The issue arises when trying to use pagination in single pages and categories using
<?php previous_posts_link('« Previous') ?>
. This script does not work as intended for these specific pages.
Below is the code snippet:
<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>More events <br/>
<span class="load_more_text"><?php next_posts_link('<img src="' . get_bloginfo('stylesheet_directory') . '/images/load-more-image.png" alt="More Events in Rome"/>', $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();
$.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');
$('#load_posts_container').append(result);
if (nextlink != undefined) {
$('.load_more_cont a').attr('href', nextlink);
} else {
$('.load_more_cont').remove();
$('#load_posts_container').append('<div class="clear"></div>');
}
if (nextlink != undefined) {
$.get(nextlink, function(data) {
if($(data + ":contains('home_post_box')") != '') {
$('#load_posts_container').append('<div class="clear"></div>');
}
});
}
}
});
});
</script>
Any suggestions or ideas for improvement?