Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Formatting, tags
Source Link
Dave Romsey
  • 17.9k
  • 11
  • 55
  • 70

iI want to add pagination in single page of custom post type..

This is the code for single page (custom post type)...

'news', 'posts_per_page' => 1, 'paged' => $paged);$loop = new WP_Query( $args);while( $loop->have_posts()): $loop->the_post();?>

// Loop

max_num_pages);previous_posts_link( 'Newer Entries');//posts_nav_link();?>

////

Function page code ////

////

add_action( 'init', 'create_post_type' ); function create_post_type() { register_post_type( 'news', array('labels' => array( 'name' => __('News', 'post type general name'), /* This is the Title of the Group / 'singular_name' => __('News', 'post type singular name'), / This is the individual type / 'add_new' => __('Add New', 'custom post type item'), / The add new menu item / 'add_new_item' => __('Add New'), / Add New Display Title / 'edit' => __( 'Edit' ), / Edit Dialog / 'edit_item' => __('Edit'), / Edit Display Title / 'new_item' => __('New '), / New Display Title / 'view_item' => __('View'), / View Display Title / 'search_items' => __('Search news'), / Search Custom Type Title / 'not_found' => __('Nothing found in the Database.'), / This displays if there are no entries yet / 'not_found_in_trash' => __('Nothing found in Trash'), / This displays if there is nothing in the trash / 'parent_item_colon' => '' ), / end of arrays / 'description' => __( 'This is the example custom post type' ), / Custom Type Description / 'public' => true, 'publicly_queryable' => true, 'exclude_from_search' => false, 'show_ui' => true, 'query_var' => true, 'menu_position' => 2, / this is what order you want it to appear in on the left hand side menu / 'capability_type' => 'post', 'hierarchical' => false, 'rewrite' => array('slug' => 'news', 'with_front' => true ), 'has_archive' => true, / the next one is important, it tells what's enabled in the post editor */ 'supports' => array( 'title', 'editor', 'thumbnail') ) );:

}

<?php
    $paged = get_query_var('paged') ? get_query_var('paged') : 1;
    $args = array('post_type' => 'news', 'posts_per_page' => 1, 'paged' => $paged);
    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post();
?>

// Loop

<?php endwhile; wp_reset_postdata(); ?>

<div id="pagination" class="clearfix">
    <?php next_posts_link( 'Older Entries', $loop->max_num_pages );
previous_posts_link( 'Newer Entries' );//posts_nav_link(); ?>
</div>

////

Function page code ////


////

add_action( 'init', 'create_post_type' );
function create_post_type() {
    register_post_type( 'news',
        array('labels' => array(
            'name' => __('News', 'post type general name'), /* This is the Title of the Group */
            'singular_name' => __('News', 'post type singular name'), /* This is the individual type */
            'add_new' => __('Add New', 'custom post type item'), /* The add new menu item */
            'add_new_item' => __('Add New'), /* Add New Display Title */
            'edit' => __( 'Edit' ), /* Edit Dialog */
            'edit_item' => __('Edit'), /* Edit Display Title */
            'new_item' => __('New '), /* New Display Title */
            'view_item' => __('View'), /* View Display Title */
            'search_items' => __('Search news'), /* Search Custom Type Title */
            'not_found' =>  __('Nothing found in the Database.'), /* This displays if there are no entries yet */
            'not_found_in_trash' => __('Nothing found in Trash'), /* This displays if there is nothing in the trash */
            'parent_item_colon' => ''
        ), /* end of arrays */
            'description' => __( 'This is the example custom post type' ), /* Custom Type Description */
            'public' => true,
            'publicly_queryable' => true,
            'exclude_from_search' => false,
            'show_ui' => true,
            'query_var' => true,
            'menu_position' => 2, /* this is what order you want it to appear in on the left hand side menu */
            'capability_type' => 'post',
            'hierarchical' => false,
            'rewrite' => array('slug' => 'news', 'with_front' => true ),
            'has_archive' => true,
            /* the next one is important, it tells what's enabled in the post editor */
            'supports' => array( 'title', 'editor', 'thumbnail')
        )
    );
}

i want to add pagination in single page of custom post type..

This is the code for single page (custom post type)...

'news', 'posts_per_page' => 1, 'paged' => $paged);$loop = new WP_Query( $args);while( $loop->have_posts()): $loop->the_post();?>

// Loop

max_num_pages);previous_posts_link( 'Newer Entries');//posts_nav_link();?>

////

Function page code ////

////

add_action( 'init', 'create_post_type' ); function create_post_type() { register_post_type( 'news', array('labels' => array( 'name' => __('News', 'post type general name'), /* This is the Title of the Group / 'singular_name' => __('News', 'post type singular name'), / This is the individual type / 'add_new' => __('Add New', 'custom post type item'), / The add new menu item / 'add_new_item' => __('Add New'), / Add New Display Title / 'edit' => __( 'Edit' ), / Edit Dialog / 'edit_item' => __('Edit'), / Edit Display Title / 'new_item' => __('New '), / New Display Title / 'view_item' => __('View'), / View Display Title / 'search_items' => __('Search news'), / Search Custom Type Title / 'not_found' => __('Nothing found in the Database.'), / This displays if there are no entries yet / 'not_found_in_trash' => __('Nothing found in Trash'), / This displays if there is nothing in the trash / 'parent_item_colon' => '' ), / end of arrays / 'description' => __( 'This is the example custom post type' ), / Custom Type Description / 'public' => true, 'publicly_queryable' => true, 'exclude_from_search' => false, 'show_ui' => true, 'query_var' => true, 'menu_position' => 2, / this is what order you want it to appear in on the left hand side menu / 'capability_type' => 'post', 'hierarchical' => false, 'rewrite' => array('slug' => 'news', 'with_front' => true ), 'has_archive' => true, / the next one is important, it tells what's enabled in the post editor */ 'supports' => array( 'title', 'editor', 'thumbnail') ) );

}

I want to add pagination in single page of custom post type.

This is the code for single page (custom post type):

<?php
    $paged = get_query_var('paged') ? get_query_var('paged') : 1;
    $args = array('post_type' => 'news', 'posts_per_page' => 1, 'paged' => $paged);
    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post();
?>

// Loop

<?php endwhile; wp_reset_postdata(); ?>

<div id="pagination" class="clearfix">
    <?php next_posts_link( 'Older Entries', $loop->max_num_pages );
previous_posts_link( 'Newer Entries' );//posts_nav_link(); ?>
</div>

////

Function page code ////


////

add_action( 'init', 'create_post_type' );
function create_post_type() {
    register_post_type( 'news',
        array('labels' => array(
            'name' => __('News', 'post type general name'), /* This is the Title of the Group */
            'singular_name' => __('News', 'post type singular name'), /* This is the individual type */
            'add_new' => __('Add New', 'custom post type item'), /* The add new menu item */
            'add_new_item' => __('Add New'), /* Add New Display Title */
            'edit' => __( 'Edit' ), /* Edit Dialog */
            'edit_item' => __('Edit'), /* Edit Display Title */
            'new_item' => __('New '), /* New Display Title */
            'view_item' => __('View'), /* View Display Title */
            'search_items' => __('Search news'), /* Search Custom Type Title */
            'not_found' =>  __('Nothing found in the Database.'), /* This displays if there are no entries yet */
            'not_found_in_trash' => __('Nothing found in Trash'), /* This displays if there is nothing in the trash */
            'parent_item_colon' => ''
        ), /* end of arrays */
            'description' => __( 'This is the example custom post type' ), /* Custom Type Description */
            'public' => true,
            'publicly_queryable' => true,
            'exclude_from_search' => false,
            'show_ui' => true,
            'query_var' => true,
            'menu_position' => 2, /* this is what order you want it to appear in on the left hand side menu */
            'capability_type' => 'post',
            'hierarchical' => false,
            'rewrite' => array('slug' => 'news', 'with_front' => true ),
            'has_archive' => true,
            /* the next one is important, it tells what's enabled in the post editor */
            'supports' => array( 'title', 'editor', 'thumbnail')
        )
    );
}
Source Link

Pagination is not working in custom post type

i want to add pagination in single page of custom post type..

This is the code for single page (custom post type)...

'news', 'posts_per_page' => 1, 'paged' => $paged); $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post(); ?>

// Loop

max_num_pages ); previous_posts_link( 'Newer Entries' );//posts_nav_link(); ?>

////

Function page code ////

////

add_action( 'init', 'create_post_type' ); function create_post_type() { register_post_type( 'news', array('labels' => array( 'name' => __('News', 'post type general name'), /* This is the Title of the Group / 'singular_name' => __('News', 'post type singular name'), / This is the individual type / 'add_new' => __('Add New', 'custom post type item'), / The add new menu item / 'add_new_item' => __('Add New'), / Add New Display Title / 'edit' => __( 'Edit' ), / Edit Dialog / 'edit_item' => __('Edit'), / Edit Display Title / 'new_item' => __('New '), / New Display Title / 'view_item' => __('View'), / View Display Title / 'search_items' => __('Search news'), / Search Custom Type Title / 'not_found' => __('Nothing found in the Database.'), / This displays if there are no entries yet / 'not_found_in_trash' => __('Nothing found in Trash'), / This displays if there is nothing in the trash / 'parent_item_colon' => '' ), / end of arrays / 'description' => __( 'This is the example custom post type' ), / Custom Type Description / 'public' => true, 'publicly_queryable' => true, 'exclude_from_search' => false, 'show_ui' => true, 'query_var' => true, 'menu_position' => 2, / this is what order you want it to appear in on the left hand side menu / 'capability_type' => 'post', 'hierarchical' => false, 'rewrite' => array('slug' => 'news', 'with_front' => true ), 'has_archive' => true, / the next one is important, it tells what's enabled in the post editor */ 'supports' => array( 'title', 'editor', 'thumbnail') ) );

}