WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Pagination for Custom Post Types on Home Page (4 posts)

  1. johnfrancisco
    Member
    Posted 3 years ago #

    Hi.

    I use Custom Post Type to list projects on Home page.
    My template home page loop is :

    [Code moderated as per the Forum Rules. Please use the pastebin]

    I use Custom Post Type UI plugin to register the custom post type.
    Permalinks are set like this : /archives/%post_id%

    The "older projects" link correcly displays on home page but links to nothing :
    http://mywebsite/page/2

    I know that It should be http://mywebsite/my_home_page_slug/page/2 to work properly but I don't know how to set this up on home page.

    Any help would be great.
    Thanks.

  2. johnfrancisco
    Member
    Posted 3 years ago #

    My template home page loop is here :
    http://pastebin.com/HLAJC8wi

  3. johnfrancisco
    Member
    Posted 3 years ago #

    Hi

    I have no solutions yet.

    I explain again with another precisions:

    I use Custom Post Type to list projects.
    I use "Custom Post Type UI" plugin to register the custom post type.
    Permalinks are set like this : /archives/%post_id%
    I set in wordpress a "Portfolio" page as the front page and another page for the Blog.
    So the Portfolio page is the front_page and the Blog page is the home. (I had confirmed this by checking with is_home(); and is_front_page(); conditional tags.

    So my template loop is fine, I test it on another page and it works fine but it does not work on the front page for the reason I exposed on first post.

    The "older entries" link correctly displays on my Portfolio front page but links to nothing :
    http://mywebsite/page/2

    The reason is that It should be http://mywebsite/my_front_page_slug/page/2 to work properly, but the slug of the front_page does not appear.

    So to solve this issue, I need a way to put the slug of the static front_page (here "portfolio") to the link generated by next_posts_link(); template tag only on this specific page.

    Hope that makes sense.

    Thanks.

  4. johnfrancisco
    Member
    Posted 3 years ago #

    Found the fix here.
    It works great for me.

    so just add this as paged param of your loop :

    if ( get_query_var('paged') ) {
        $paged = get_query_var('paged');
    } else if ( get_query_var('page') ) {
        $paged = get_query_var('page');
    } else {
        $paged = 1;
    }
    query_posts( array( 'post_type' => 'post', 'paged' => $paged ) );

Topic Closed

This topic has been closed to new replies.

About this Topic