Support » Fixing WordPress » Previous Custom Post Types

  • Resolved Roy

    (@gangleri)


    I have created a template that displays custom post types based on the index.php of my theme. Then I created a page to which I assigned that template. This works fine except for the fact that the “previous” and “next” links do not work and I don’t know why. The links are correct (/page/2), but the same posts are loaded. Could anyone tell me if this is because of a mistake in the template? The template can be seen here. I later replaced the loop that you see there to set the number of displayed posts to 100 so that navigation is not needed, so the template currently uses:

    <?php
    $args = array(
    	'posts_per_page' => 100,
    	'post_type' => 'blog'
    );
    query_posts($args);
    if ( have_posts() ) : while ( have_posts() ) : the_post();
    ?>

Viewing 15 replies - 1 through 15 (of 29 total)
  • Argh, I’m pulling my hair out over this. I now have the following situation which I can even replicate:
    With the query above I have the custom post types set to displaying 100 because paging ‘next’ and ‘previous’ doesn’t work.
    About a week ago I activated PHP5 on my server in order to be able to use a plugin called “Simple Custom Post Type Archives” of which is said that (among others) it solves problems with paging and archiving of custom post types. I tried it, tested it and tested some more but I could not find a any difference between the behaviour with and without the plugin.

    I also use another plugin “Excerpt Editor” which unfortunately also excerpts the custom post types for which I use pages with the custom template with the query of my previous post and pages should not be excerpted. Too bad, but in one subsite I decided to just deactivate the excerpt editor plugin because the unexcerpted index looks less bad than an excerpted custom post type page. Then my eye fell on the active “Simple Custom Post Type” plugin and I deactivated it too. When looking at the result, I noticed that the custom post type page does not display all posts, but rather a number of 10 as set for my normal posts and archives (the WP setting) and the pagination worked!! Trying to figure out how this miraculously started working I looked at some other custom post type pages (which still don’t work), noticed that the same templates but with a different name that I created for the “Simple Custom Post Type Archive” plugin was selected for one custom post type and not for another. These templates have no difference in content, just in file name, so I figured that may this in the end was the trick of the “Simple…” plugin afterall, but you know what? It only works when I deactivate that plugin and as soon as I looked at the template file again, it just starts malfunctioning like it used to.

    All thoughts are welcome, but I would be especially happy to hear from people who use custom post types and managed to get the ‘previous’ and ‘next’ links to work and how. I still get alternally just a reloaded page 1 with a different permalink and a 404. I haven’t found the logic in that yet.

    [edit] Hm, I can only replicate this with one custom post type in one subsite (but I’ve already did it 4 times). Still it proves that custom post type pagination can work, I only need to figure out how…

    So I can replicate this. I just set up a new test subsite, created a custom post type and a page displaying them. Navigation doesn’t work. Then I activate the “simple custom post type archives” plugin, navigation still doesn’t work, but page 2 is a refreshed page 1 instead of a 404. Then I deactivate the plugin and navigation works but the custom post types behave like a normal index instead of query set to display a certain number. Now I don’t mind that, but I still need to find a way to make this happen on all custom post types on the live subsites. The Excerpt Editor plugin has nothing to do with all this, it just happened to be the plugin I was working with when I discovered that can work some way. A how and why would still be nice though 🙂

    The ‘patch’ sometimes works, sometimes it doesn’t. It would still be nice to know how to get the previous and next links to work by defaults. Any suggestion is welcome.

    I had the same problem, previous and next links don’t work on pages

    <?php
    global $more;
    $more = 0;
    ?>
    
    			<?php the_content('<span class="details">Additional Details</span>'); ?>

    drop that bit of code above the_content as I’ve shown

    Rev, thanks for your reply! This little bugger is the major issue (with several smaller following to be solved) with custom post types. Unfortunately, it doesn’t make a difference, but I’m sure that’s me.

    I’ve put

    <?php
    global $more;
    $more = 0;
    ?>

    Above

    <div class="postentry">
    <?php the_content(__('Continue reading').

    etc

    and between these two lines, but the first posts appear on every next and previous page.

    Sorry, I’m no coder……….

    dood….I totally gave you the wrong info…. sorry, I’ve been working on getting the ‘read more’ to work, and pagination with my custom post types and taxonomies.

    I read what you wrote, and then totally didn’t answer your quest8ion. The code I gave is to get the read more to work on pages. Let me look through what I’ve done over the past 2 days to get you the right answer

    Sorry about that

    <?php query_posts(array(
                'post_type' => 've_products', // can be custom post type
                'paged'=>$paged, 
    
            ));
    
            ?>

    its this part here you need
    'paged'=>$paged,

    Sorry again.

    <?php
    $args = array(
    	'posts_per_page' => 5,
    	'post_type' => 'blog'
    	'paged'=>$paged,
    );
    query_posts($args);
    if ( have_posts() ) : while ( have_posts() ) : the_post();
    ?>

    Gives a white screen. You example has no loop and I’m not sure how to use it.

    YYEEEEEAAAAAAAAHHHHHHHHHHHH!!!!!!!!!!!!!!!!!!!!!!!!!!
    Rev, you’re up five place on the list 🙂

    Now I can start to think about those other custom post type things, but not today.

    Thanks man, you’ve made my month.

    Hmm, something fishy on my other custom post type. See way below.

    What are the other things you’ve been looking into? The more tag? Custom taxonomies? Recent custom post types in a widget? 🙂

    Be back tomorrow.

    Hmmm…your previous and next post link both seemt o point to the same page… is that what you mean? I’ll have to look into the pagination stuff a bit more

    I’ve been working on:
    Custom post types
    Custom taxonomies
    More tag on a page of custom posts
    Displaying the custom taxonomy on the post (ie: This product was listed in Clothing)
    using special templates for single view of custom taxonomies

    I think that’s it. I’ve googled my butt off the past few days trying to convert my old standalone eshop to be included in my main WP site using all the above stuff

    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts(array(
    	'post_type' => 've_products', // custom post type
             'paged'=>$paged,
            ));
    ?>

    I updated my above code to this, to test whether the ‘paged’ query variable is available.

    If it isn’t, we’re on the first page and assign it ‘1’. Then we tell query_posts() what page we’re on with &paged=$paged.

    It works for me….. dunno if it’ll help ya at all (I put that stuff above my <?php if (have_posts()) : ?> stuff)

    The weird thing is, the first custom post type (“blog”) works perfectly. The blogs that do have have enough posts to have to page just don’t have the previous and next links, but the “quotes” custom post type gives previous and next links (that don’t work) by default (also with the new code). The page I use is entirely the same, safe for the ‘post_type’ => etc.
    Weird, but a MUCH smaller issue than when no custom post type page paged.

    [edit] this “quotes” page should page since there’s a couple of more coming. The ‘previous posts’ link gives a ‘what you are looking for is not here’ (my theme’s 404 so to say).

    [edit again] the only difference between the c.p.t.’s “blog” and “quotes” seems to be that I have tried working with custom taxonomies in the latter, but removing those (they didn’t work anyway) doesn’t help.

    That’s strange. I only have one custom post type atm. But the pagination works perfectly. I just recently started using custom post types….. I’m no expert. Is there anything in the actual post type setup that could jack up pagination? I mean…something has to be conflicting…. Here’s how I set up my post type….. or are you using a plugin to do it?

    // ADDS CUSTOM PRODUCTS POST TYPE SO WE CAN USE SINGLE PAGE TEMPLATE
    add_action( 'init', 'create_post_type' );
    function create_post_type() {
      register_post_type( 've_products',
        array(
          'labels' => array(
            'name' => __( 'Products' ),
            'singular_name' => __( 'Product' ),
            'add_new' => _x('Add New', 've_products'),
            'add_new_item' => __('Add New Product'),
            'edit_item' => __('Edit a Product'),
            'new_item' => __('New Product'),
            'view_item' => __('View a Product'),
            'search_items' => __('Search Products'),
            'menu_icon' => get_stylesheet_directory_uri() . '/images/voodooTitleDefault.png',
            'not_found' =>  __('No products found'),
            'not_found_in_trash' => __('No products found in Trash'),
            'parent_item_colon' => ''
          ),
            'public' => true,
            'rewrite' => true,
            'supports' => array( 'title', 'editor', 'comments', 'excerpt', 'custom-fields', 'thumbnail' ),
        )
      );
    }

    Rev, like I said, I’m no coder. In fact, I only discovered custom post types when I ran into a plugin that makes them! The settings of the ‘blog’ and ‘quotes’ c.p.t.s are exactly the same, so I have no idea. No worries though, I have a ‘blog’ in every subsite, but only one with ‘quotes’.

    Other things to look into are going to be the ‘more’ tag and maybe custom taxonomies, but perhaps I’ll make it so I won’t need them. When you’ve got these things figured out, would it be an idea to put them in the codex? There are plenty people struggling with cpt’s and that sollution for the pagination might already help many.

Viewing 15 replies - 1 through 15 (of 29 total)
  • The topic ‘Previous Custom Post Types’ is closed to new replies.