tbkcp_ajax_pagination.php

Summary
tbkcp_ajax_pagination.php
Displays a numbered pagination list and retrieves the posts via ajax on-click
tbkcp_ajax_paginationDisplays a numbered pagination list and retrieves the posts via ajax on-click
Functions
__constructAdds wp_ajax actions to retrieve posts.
retrieve_postsWill retrieve the post list depending on the pagination # clicked
paginateDisplays the numbered pagination, prints the jquery for the click actions

Displays a numbered pagination list and retrieves the posts via ajax on-click

  • Author: Paul MacLean*
  • Usage Example:*
//Get the first set of posts, putting it inside an ajax_content wrapper (changeable: see function paginate parameters)
<ul id ="ajax_content">
<?php
$query_args = array(
'cat' => '42',
'posts_per_page' => 10,
);
$loop_pages = new WP_Query($args);
while ($loop_pages->have_posts()) : $loop_pages->the_post();
the_event_item();
?>
<?php
endwhile;
?>
</ul>
//If in a theme you need to access the global $included_modules set in tbkcp_client_plugin.php which stores all of the tbkcp internal class references
global included_modules;
//Check if the module has been enabled
if (class_exists('tbkcp_ajax_pagination')) {

$tap = $included_modules['tbkcp_ajax_pagination'];
//Will place the numbered pagination and print the necessary scripts
$tap->paginate($query_args, $user_func = 'the_event_item')

}
//The single item content inside the loop
function the_event_item() {
?>
<li class ="event_item">
<h2><?php the_title() ?></h2>
<?php the_content() ?>
</li>
<?php
}

tbkcp_ajax_pagination

Displays a numbered pagination list and retrieves the posts via ajax on-click

Summary
Functions
__constructAdds wp_ajax actions to retrieve posts.
retrieve_postsWill retrieve the post list depending on the pagination # clicked
paginateDisplays the numbered pagination, prints the jquery for the click actions

Functions

__construct

function __construct()

Adds wp_ajax actions to retrieve posts.

retrieve_posts

function retrieve_posts()

Will retrieve the post list depending on the pagination # clicked

paginate

function paginate($new_args)

Displays the numbered pagination, prints the jquery for the click actions

Parameters:
@query_args : the wp_query args to retrieve the posts
@user_func : the single item markup for inside the loop (note if a class function, still only use the name of the function not array($this,function_name))
@class_name : the name of the class if user_func is in a class (note, this class will need to be set as a global var)
@query_type: What type of loop you are using, default 'query_posts'. Can be 'wp_query'
@container_id : the wrapper for the posts section that will refresh
@filter:  adds the  add_filter('posts_where', 'filter_where') filter;
@taxonomy: can be used with custom taxonomies
function __construct()
Adds wp_ajax actions to retrieve posts.
function retrieve_posts()
Will retrieve the post list depending on the pagination # clicked
function paginate($new_args)
Displays the numbered pagination, prints the jquery for the click actions
Close