WordPress.org

Ready to get started?Download WordPress

Forums

Pagination and Loop for Custom Post Type (4 posts)

  1. Xiou
    Member
    Posted 1 year ago #

    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".

    <?php

    $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();
    ?>
    
    <article>
     MY CONTENT
    </article>
    
    <?php endwhile; ?>
    
      <nav>
        <div class="nav_post"><?php previous_posts_link("&laquo; Précédants") ?></div>
        <div class="nav_post"><?php next_posts_link("Suivants &raquo;") ?></div>
      </nav>
    
    <?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 ?

  2. Pioneer Valley Web Design
    Member
    Posted 1 year ago #

    Both of these links should help you build a Custom Post Type Page Template with Pagination.

    http://codex.wordpress.org/Pages#Example_Using_Custom_Post_Types
    http://wordpress.org/support/topic/page-of-posts-and-pagenavi?replies=5

  3. Xiou
    Member
    Posted 1 year ago #

    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)
    qwerty.com/blog/
    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.
    qwerty.com/blog/page/2/

    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 ?

  4. Xiou
    Member
    Posted 1 year ago #

    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 ?

Topic Closed

This topic has been closed to new replies.

About this Topic