Code snippet of 5 word press pagination with examples [from simple to advanced]

To specify a paging style based on the theme style
\/**Specifies the CSS class of the paging style**
Navigation{
}
Navigation{
}
#3) WordPress Ajax paging example WordPress if you are looking for Ajax paging code, you can find a well running example in GitHub. The code is in plug-in format. I have customized it. I can copy it to a file, save it in ZIP format, and install it as a plug-in to make it a plug-in in our tutorial. The following is the word press Ajax paging example code:
num_per_page = 5;
$this – > initialization ();
}
Protected function init (){
Add_action (\
add_filter( ‘query_vars’, array( $this, ‘add_query_vars’ ) );
add_action( ‘parse_request’, array( $this, ‘parse_request’ ) );
}
\/**
*Parse incoming requests and generate results.
*\/
Function parse_request ($WP){
if ( array_key_exists( ‘cs-page’, $wp->query_vars ) ) {
$page = isset ( $wp->query_vars[‘cs-page’] ) ? $ wp->query_vars[‘cs-page’] : 1;
$args = array(
\
‘post_per_page’ => $this->num_per_page,
\
);
$query = new wp_query ($args);
\/\/Need to know the total number of Posts found.
$values[‘total’] = $query->found_posts;
\/\/Then each page.
$values[‘per_page’] = $this->num_per_page;
$values [\
\/\/Send only the required data.
Period ($query – > have_posts){
$query->the_post();
$values [\
‘ID’ => get_the_ID(),
\
);
}
wp_reset_postdata();
Wp_send_json ($value);
}
}
\/**
*Add the required query factor.
*\/
Function add_query_vars ($query_vars){
$query_vars[]=“cs-page”;
$query_vars returns;
}
\/**
*Add rewrite rules for custom paging to avoid using admin Ajax.
*\/
Function add_rewrite_rule(){
add_rewrite_rule( ‘^cs-paginate\/([0-9]+)\/?’, ‘ index. php? CS page = $matches [1] \
}
\/**
*Refresh rewrite rule.
*\/
Install static functions (){
flush_rewrite_rules();
}
}
Function njengah_ajax_pagination_init(){
New njengah_ajax_pagination();
}
njengah_ajax_pagination_init();
\/\/The override rule must be refreshed when activated.
Register_activation_hook (_file_, array (\
#4) Custom word press pagination of post type custom post type pagination:

Author:

Leave a Reply

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