Support » Fixing WordPress » Pagination and Loop for Custom Post Type

  • Hi,

    I’m currently using Magic Fields2 to use Custom Post Types, WPML for multilingual and few others which are not related to my problem.

    I would like to render posts on the blog page, with 8 post per page (currently, I use 1 to do tests).

    I had some fields to the original post type and so I now have to use it as a custom post type.

    I’ve got some difficulties to do an effective pagination which lead to something else to a 404 page.

    I’ve read many supports on this subject, as post-1 and post-2 and few others but I can’t find the solution.

    Here is my code currently, but It doesn’t stop moving to find a solution.

    My page where this code is written is called “blog” and the origin post type is called “post”.


    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $wp_query = new WP_Query();
    $wp_query->query('post_type=post&posts_per_page=1'.'&paged=' . $paged);
    if ($wp_query->have_posts()) :
    while ($wp_query->have_posts()) : $wp_query->the_post();
    <?php endwhile; ?>
        <div class="nav_post"><?php previous_posts_link("&laquo; Précédants") ?></div>
        <div class="nav_post"><?php next_posts_link("Suivants &raquo;") ?></div>
    <?php endif; ?>

    Does someone would help me to figure out how to implement a good pagination (numbers/previous-next) ?
    And after this first step, how to setup this page/2/ without to go on a 404 page ?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Both of these links should help you build a Custom Post Type Page Template with Pagination.

    Thanks to you and the links you gave me, I now have a pagination.

    But it’s a little more complicated :

    I’m on my Blog page (which is display by index.php)
    2 articles are printed (post_per_page 2 for the example)
    The pagination is ok with 2 pages (3 articles total).

    My problem is when I try to go on the page 2, I’ve got a 404 error.

    I already saw this problem in other posts when the custom post type is called blog and the page is called blog. This is not my case.
    I use “Blog” as page.
    I use the original WordPress Posts as articles (where I added two fields thanks to Magic Fields 2).

    Do you have any idea of what it could be ?

    Some news :

    Reminder : I can not reach the page 2 of my Blog

    My previous configuration :
    Permalink settings : – Postname : /%postname%/
    Reading Settings : static page : Post Page – Blog

    The only configuration “working” :
    Permalink settings : – Default : ?p=123
    Reading Settings : static page : Post Page – Select (none)

    I can reach the second page of my posts using : ?page_id=23&paged=2
    but I really don’t want to use the Permalink Default setting

    Does someone has an idea of what is going on ?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Pagination and Loop for Custom Post Type’ is closed to new replies.