Hi @jrmyptrs,
You can do this without the Previous Post add-on. That is specifically for displaying the entire single post.
Just drop the echo do_shortcode('[ajax_load_more]'); shortcode into your single template and you can load additional posts.
Hope this helps.
Cheers,
Thread Starter
jrmyp
(@jrmyptrs)
Fantastic, thank you so much for that Darren.
One tip I’d add for anyone who else who comes across this, just be sure to include the “offset” parameter in your shortcode to avoid showing the current post in the loop, e.g.:
echo do_shortcode('[ajax_load_more offset='1']');
Thread Starter
jrmyp
(@jrmyptrs)
Actually – scratch that, the offset appears to only work for the very first post.
@dcooney, is there something I can do to make that loop always exclude the current post and any posts that are newer than the current post?
-
This reply was modified 9 years, 4 months ago by
jrmyp.
You’ll need to pass the current post id to the shortcode.
Have a look at the post__not_in parameter or the excluding posts example inside the plugin.
Cheers,
Thread Starter
jrmyp
(@jrmyptrs)
Thanks for all your help @dcooney, I was able to remove the current post by using the get_the_ID(); function and storing that as a variable as your excluding posts example showed.
Any suggestions on how to filter out any posts that are newer than the current single post?
Thread Starter
jrmyp
(@jrmyptrs)
Posting the code solution for anyone else who needs to do something similar.
First, you’ll need to go into your functions.php file and add the following function:
function my_alm_query_args_date_after($args){
if(isset($args['the_date'])){
$date = date('Y-m-d H:i:s', $args['the_date']); // Get date timestamp and convert to readable format
$args['date_query'] = array(
array(
'before' => $date,
),
);
}
return $args;
}
add_filter( 'alm_query_args_date_after', 'my_alm_query_args_date_after');
Then, in single.php, the shortcode:
<?php
$current = get_the_ID();
$postDate = get_the_date('Y-m-d H:i:s');
$date = strtotime($postDate);
echo do_shortcode('[ajax_load_more id="date_after" custom_args="the_date:'. $date .'" exclude="'.$current.'"]');
?>
Works like a charm.
-
This reply was modified 9 years, 4 months ago by
jrmyp.