Created
March 1, 2012 21:56
-
-
Save da1nonly/1953507 to your computer and use it in GitHub Desktop.
Twitter like next post load for Wordpress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action('wp_ajax_and_action', 'add_next_post'); | |
function add_next_post() | |
{ | |
$query_string = $_POST['query_string']; | |
$offset = $_POST['paged'] * get_settings('posts_per_page'); | |
$per_page = get_settings('posts_per_page'); | |
query_posts("$query_string&offset=$offset&posts_per_page=$per_page"); | |
get_template_part( 'loop', 'paginate' ); | |
die(); | |
} | |
add_filter('wp_footer', 'javascript_page'); | |
function javascript_page() { | |
global $query_string; | |
?><script type="text/javascript"> | |
jQuery(document).ready(function($) { | |
var ajaxurl = '<?php echo home_url(); ?>/wp-admin/admin-ajax.php'; | |
var page_number = 2; | |
var busy = false; | |
$('.loading-more').bind('click', function(e) { | |
busy = true; | |
$('.loading-more').html('<em>Loading more posts..</em>') | |
$.post(ajaxurl, { | |
action: 'and_action', | |
query_string: '<?= $query_string ?>', | |
paged: page_number | |
}, function(data) { | |
if (data == '') { | |
$('.loading-more').html('<strong>No more posts!</strong>'); | |
} else { | |
$('.empty-div').append(data); | |
busy = false; | |
$('.loading-more').html('<em>Load more posts</em>'); | |
page_number += 1; | |
} | |
}); | |
}); | |
}); | |
</script> | |
<?php } ?> | |
// Add to index.php template | |
// <div class="empty-div"></div> | |
// <div class="loading-more span12"></div> | |
// twitter bootstrap |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment