WordPress.org

Ready to get started?Download WordPress

Forums

Problem with using paging for custom post type (3 posts)

  1. SZ4H
    Member
    Posted 1 year ago #

    Hello
    I have a problem showing my category page in pageing
    I have a custom post type named 'videos'
    I put all the posts of this type in a one category names 'cars video'
    I use a template page category-9.php' as the id of this category 'cars video' is '9'

    I place this code at the top of my loop

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    ?>
    		<?php query_posts( $query_string . '&post_type=videos&posts_per_page=10&paged=' . $paged ); ?>
    		<?php if ( have_posts() ) : ?>
    			<?php
    			/* Start the Loop */
    			while ( have_posts() ) : the_post();
    etc.......

    I got the first page 'sitename.com/blog/category/cat-videos/' working fine but I have this pages not working
    'sitename.com/blog/category/cat-videos/page/1'
    'sitename.com/blog/category/cat-videos/page/2'
    etc..

    it gave me 404.php page

    Any advices?

  2. SZ4H
    Member
    Posted 1 year ago #

    Thanks I solved it

    the problem was not in query or the paging but I used category-9.php template page
    but I fixed it by using archive-videos.php

    Thanks

  3. Mohsin Patel
    Member
    Posted 3 months ago #

    Glad that you make it resolved. My personal openion for paging is don't use custom code rather then use wordpress number paging fuction tio replace previous /mnext links

    very few people knowing about this inbuilt function

    <?php
    global $wp_query;
    $big = 999999999; // need an unlikely integer
    echo paginate_links( array(
    'base' => str_replace( $big, '%#%', get_pagenum_link( $big ) ),
    'format' => '?paged=%#%',
    'current' => max(2, get_query_var('paged') ),
    'total' => $wp_query->max_num_pages,
    'show_all' => false,
    'prev_next' => True,
    'prev_text' => __('« Previous'),
    'next_text' => __('Next »')
    ) );?>

    For replace ment technique you can find more details here -

    http://www.shoutgeek.com/how-to-add-numeric-pagination-wordpress-theme/

    Above WordPress function works with custom post-type as well :)

    For more parameters and related arguments check
    http://codex.wordpress.org/Function_Reference/paginate_links

    Thanks

Topic Closed

This topic has been closed to new replies.

About this Topic