Hmmm, I undid what I did above, as it was pretty pointless.
I tried to display how many posts were being displayed using count($posts), which always came out as 10, which is what I set in the reading prefs.
The theme generated the first 10 posts in the index.php file, while the following posts loaded are generated in the functions file. Is this normal?
index
<?php
global $more; $more = 0;
?>
<?php if (have_posts()) : while ( have_posts() ) : the_post(); ?>
<div class="masonr">
<div <?php post_class('post'); ?>>
<!-- uses the post format -->
<?php
if(!get_post_format()) {
get_template_part('format', 'standard-small');
} else {
$format = get_post_format();
if ($format == 'image') {get_template_part('format', 'image-small');}
else if ($format == 'gallery') {get_template_part('format', 'gallery-small');}
else {get_template_part('format', $format);}
}
?>
</div><!-- post-->
</div>
<?php endwhile; ?>
functions
//----------------------------------- // Load More AJAX Call //----------------------------------- //
if(!function_exists('cr_load_more')){
add_action('wp_ajax_cr_load_more', 'cr_load_more');
add_action('wp_ajax_nopriv_cr_load_more', 'cr_load_more');
function cr_load_more(){
if(!wp_verify_nonce($_POST['nonce'], 'cr_ajax')) die('Invalid nonce');
if( !is_numeric($_POST['page']) || $_POST['page']<0 ) die('Invalid page');
$args = '';
if(isset($_POST['archive']) && $_POST['archive']){
$args = $_POST['archive'] .'&';
}
$args .= 'post_status=publish&posts_per_page='. get_option('posts_per_page') .'&paged='. $_POST['page'];
if(isset($_POST['archive']) && $_POST['archive'] && strlen(strstr($_POST['archive'],'post-format'))>0){
$args = array(
'post_status' => 'publish',
'tax_query' => array(
array(
'taxonomy' => 'post_format',
'field' => 'slug',
'terms' => $_POST['archive']
)
),
'posts_per_page' => get_option('posts_per_page'),
'paged' => $_POST['page']
);
}
ob_start();
$query = new WP_Query($args);
while( $query->have_posts() ){ $query->the_post();
?>
<div class="masonr">
<div <?php post_class('post'); ?>>
<?php
if(!get_post_format()) {
get_template_part('format', 'standard-small');
} else {
$format = get_post_format();
if ($format == 'image') {get_template_part('format', 'image-small');}
else if ($format == 'gallery') {get_template_part('format', 'gallery-small');}
else {get_template_part('format', $format);}
}
?>
</div><!-- post-->
</div>
<?php
}
wp_reset_postdata();
$content = ob_get_contents();
ob_end_clean();
echo json_encode(
array(
'pages' => $query->max_num_pages,
'content' => $content
)
);
exit;
}
}
?>