• Resolved dkristine

    (@dkristine)


    I am fairly new to wordpress and a total PHP newbie… What I want to be able to do is display 9 post thumbnails from a custom post type, and have a pager at the bottom. Here is an excerpt of my template code:

    <div id="content" role="main" class="entry-content">
    
    <?php $loop = new WP_Query( array( 'post_type' => 'accessories', 'posts_per_page' => 9, 'orderby'=> menu_order) ); ?>    
    
    <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
    <div class="accessory_image"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php if ( function_exists("has_post_thumbnail") && has_post_thumbnail() ) { the_post_thumbnail(array(200,160)); } ?></a>
            <?php the_title( '<h3 class="accessory-title"><a href="' . get_permalink() . '" title="' . the_title_attribute( 'echo=0' ) . '" rel="bookmark">', '</a></h3>' ); ?>
    </div>
    <?php endwhile; ?>
    <div class="navigation">
      <div class="alignleft"><?php previous_posts_link('&laquo; Previous') ?></div>
      <div class="alignright"><?php next_posts_link('More &raquo;') ?></div>

    The “more” and “previous” links are there, and the “more” link does point to “our_accessories/page/2” (I realized I couldn’t name the page the same as the content type)

    But the same items show on each page.

    Anyone have any insight?

    Thanks!!

    Dani

Viewing 14 replies - 31 through 44 (of 44 total)
  • hi,

    I am having this problem, I have installed the plugin fix and that has fixed the 404 error although when I try to page it goes to the main blog page (News – which is not a custom post type)

    My custom Post Type is named ‘Work Items’

    I have tried adding this code to my page but it didn’t work:
    [Code moderated as per the Forum Rules. Please use the pastebin]

    I’m back on this thread after months, I’m glad a lot of people managed to find it and get helped ??

    @vayu the global variable,

    global $wp_query

    changes according to the URL that your HTTP request is requiring. If you are going to custom modify its behaviour inside a page (eg: listing a custom post type), you NEED to reset it using

    wp_reset_query();

    so no parameters from the HTTP request get in the way of your custom query.

    @jbiddulph

    put this code in your functions.php
    https://rafaelxy.pastebin.com/VtHQEkH7

    and use this custom_query_posts() function instead of “new WP_Query()” or “query_posts()”

    just remember to pass the params as an array, and not as a query string.

    Thanks rafaelxy!

    I appreciate the explanation and tip. ??

    Thanks for the tip on having the page name and post type name different.

    I just have one question: If I name the post type something like “my-projects” and name the page “projects”, the link points to mysite.com/my-projects/ instead of mysite.com/projects

    Anyway I can fix this?

    I’m trying without success all solution, also @rafaelxy solution.
    Pagination links don’t appear.

    Sorry but custom_query_posts must add in function or is good in template page too?

    Thanks

    Sorry: now it works. I put function on template. First I wronged args array. Little question: why function and not plain code?

    Thanks.

    Great..!!!

    Thanks Colleagues…

    Thank you Very Much.. ??

    I found the answer here.

    Basically, you need to make sure the ‘Blog pages show at most’ item in Settings->Reading is low enough so there are at least that many posts on the final page of your custom page loop. For instance, if your setting is 15 and there are only 5 posts on the final page of your loop, you’ll get a 404.

    If there’s a way to override this in your custom query, please let me know.

    Note: Oddly, if you’re logged in as an admin the pagination seems to work correctly.

    @lancemonotone: THANKS!! It was the freaking Settings > Reading issue which caused the 404 page. What the… I finally got everything working. Pff

    @rafaelxy DUDE THANKS A LOT!! KEEP IT UP! ^^

    i’m trying without succes.. ?? i use this code

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

    but don’t work.. ??

    i have past the code on https://pastebin.com/sPvVgseA

    I Just want to thank TakeoK, your code works for me, thanks!

Viewing 14 replies - 31 through 44 (of 44 total)
  • The topic ‘Pagination with custom post type listing’ is closed to new replies.