• Resolved jrue

    (@jrue)


    Is there a way to query for liveblog comments for the front page?

    Our site is setup so the front page just shows excerpts to each post. I would like to write a custom template to get a few of the most recent liveblog entries and put them on our front page.

    ‘get_comments()’ doesn’t work, because the post_meta still thinks there are zero comments on the article (which there are if you’re counting non-liveblog comments.)

    I was thinking it would be nice to get that JSON feed via ajax, this way we could update the front without messing with our caching system.

    Thanks for any advice. I’ll keep digging and I will respond to my own question if I find a solution before I get a reply. Thanks

    – Jeremy

    http://wordpress.org/extend/plugins/liveblog/

Viewing 1 replies (of 1 total)
  • Thread Starter jrue

    (@jrue)

    OK, I figured it out. I haven’t done too much with WordPress’s ajax hooks, so it took me a little bit of deciphering.

    For others who might want to do the same thing, it’s actually quite simple and done completely with JavaScript. If you query the URL of the post along with two timestamps—a from value and a to value—it will return the liveblog posts between those two values in JSON format.

    Here is the script I came up with for my purposes if it’s helpful to anyone. I just used 1 as my from value, to retrieve all posts. This probably isn’t very efficient at all, but it made it easy for me so I can display truncated versions of the top four or five liveblog posts for our front page to entice readers to click in.

    Anyone implementing this, I would encourage you to look at liveblog.js which has some fantastic timer scripts if you wanted to keep it livestreaming, similar to how it was built.

    Oh, and the code below is within the loop, and only works with permalinks that don’t use query strings:

    <?php if(class_exists('WPCOM_Liveblog') && (bool) get_post_meta($post->ID, 'liveblog', true)): ?>
    <script type="text/javascript" >
    jQuery(document).ready(function($) {
    
    	function success_callback(response, status, xhr){
    		console.log(response.entries);
    	}
    
    	function error_callback(response){
    		console.log(response);
    	}
    
    	function current_timestamp() {
    		return Math.floor( Date.now() / 1000 );
    	};
    
    	$.ajax( {
    		url: '<?php the_permalink(); ?>liveblog/1/' + current_timestamp() + '/',
    		data: {},
    		type: 'GET',
    		dataType: 'json',
    		success: success_callback,
    		error: error_callback
    	} );
    });
    </script>
    <?php endif; //end liveblog ?>
Viewing 1 replies (of 1 total)
  • The topic ‘Query liveblog comments for front page?’ is closed to new replies.