Ajax to know if it’s frontpage and $do_not_duplicate?

I’m changing my frontpage to “lazy load” content. And in functions.php I have coded a function that creates the content with the content; headlines, preambles, images. The problem is that this content was dynamically created earlier. So there was different arguments sent based on if it was the frontpage or not. I used the is_home() to check that. And I also used the $do_not_duplicate variable to ensure there can’t be duplicated posts on the frontpage. And these things doesn’t work with ajax. I know that. But what options do I have here? Think this must be a pretty common issue and that WordPress maybe have thought of this as with much other things in the framework?

Here is the ajax part in the javascript lazy load function:

jQuery.get(ajaxurl + ‘?action=show_box&box=top-story-news’, function(data)
var response = jQuery(data);
var datas = { content : response };

return callback(datas, key);

and here is the php code in functions.php:

function show_box()
global $post, $do_not_duplicate;

$box = $_GET[‘box’];

switch ($box)
case ‘top-story-news’:

$args = array(
‘name’ => ”,
‘slug’ => is_home()?’top-story’:”,
‘boxsize’ => ‘medium’,
‘imagesize’ => ‘small’,
‘posts’ => 2,
‘days’ => 1
echo get_boxes($args, 2, ‘top-story-news’);


add_action( ‘wp_ajax_show_box’, ‘show_box’ );

Read more here:: Ajax to know if it’s frontpage and $do_not_duplicate?

Leave a Reply

Your email address will not be published. Required fields are marked *