WordPress.org

Forums

[resolved] Previous Custom Post Types (30 posts)

  1. Roy
    Member
    Posted 5 years ago #

    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();
    ?>
  2. Roy
    Member
    Posted 5 years ago #

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

  3. Roy
    Member
    Posted 5 years ago #

    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 :-)

  4. Roy
    Member
    Posted 5 years ago #

    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.

  5. Rev. Voodoo
    Volunteer Moderator
    Posted 5 years ago #

    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

  6. Roy
    Member
    Posted 5 years ago #

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

  7. Rev. Voodoo
    Volunteer Moderator
    Posted 5 years ago #

    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

  8. Rev. Voodoo
    Volunteer Moderator
    Posted 5 years ago #

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

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

  9. Roy
    Member
    Posted 5 years ago #

    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.

  10. Roy
    Member
    Posted 5 years ago #

    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.

  11. Roy
    Member
    Posted 5 years ago #

    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.

  12. Rev. Voodoo
    Volunteer Moderator
    Posted 5 years ago #

    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

  13. Rev. Voodoo
    Volunteer Moderator
    Posted 5 years ago #

    <?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)

  14. Roy
    Member
    Posted 5 years ago #

    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.

  15. Rev. Voodoo
    Volunteer Moderator
    Posted 5 years ago #

    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' ),
        )
      );
    }
  16. Roy
    Member
    Posted 5 years ago #

    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.

  17. Rev. Voodoo
    Volunteer Moderator
    Posted 5 years ago #

    http://net.tutsplus.com/tutorials/wordpress/introducing-wordpress-3-custom-taxonomies/

    I used that for my custom taxonomies, just knowing that here:
    register_taxonomy( 'operating_system', 'post', array

    instead of post, I used ve_products since that was my custom post type, that way the new taxonomy menu is on the custom post type page

    And, the more tag was this bit of code I accidentally gave you earlier

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

    basically that is needed whenever you use a page and want to use the more tag

    So if you use a page template to display your custom post types like I do, you would need that for the more to work

  18. Roy
    Member
    Posted 4 years ago #

    That works perfectly Rev! Thanks again. It took a while before I could try.
    The plugin that I use can make custom taxonomies perfectly, but just as with these other things, they don't work. When I make a custom post type 'quotes' and a custom taxonomy 'from' and I asign the taxonomy 'dumezil' to a quote, the link of the custom taxonomy will not be website/quotes/from/dumezil, but website/dumezil and that (of course) doesn't work well.

    [edit] Just forget about the taxonomies. I managed to use them similar to categories and tags, but not anymore. There are things above this point on the priority list.

  19. tshirtfiend
    Member
    Posted 4 years ago #

    Would one of you guys mind summarizing the changes that you made to create Next/Prev links? It's a little hard to follow the thread completely.

    I'm having a similar issue: I have a CPT with a custom taxonomy. The taxonomy terms show up in a menu that I created, but clicking on the terms in the menu displays an archive of that term. And there's no way to really navigate through the posts that I can figure out.

    I'd appreciate any help.

  20. Rev. Voodoo
    Volunteer Moderator
    Posted 4 years ago #

    does the template you are using have a previous and next post link?

    something like:

    <div class="alignleft"><?php next_posts_link(__('&laquo; Older Entries')) ?></div>
    			<div class="alignright"><?php previous_posts_link(__('Newer Entries &raquo;')) ?></div>
  21. tshirtfiend
    Member
    Posted 4 years ago #

    Yup. This is what I'm using:

    <div class="nav-previous"><?php next_posts_link(__('<span class="meta-nav">&laquo;</span> Previous item', 'thematic')) ?></div>
    				<div class="nav-next"><?php previous_posts_link(__('Next item <span class="meta-nav">&raquo;</span>', 'thematic')) ?></div>

    It's a thematic child theme.

  22. Rev. Voodoo
    Volunteer Moderator
    Posted 4 years ago #

    ah...I know nothing about thematic.

    That code should work as long as its in the proper location. mine's above the comment form, above the endwhile

    Not sure what sort of options menu that theme has....like if there is an option to turn off pagination

    Also, not trying to be a smart ass or anything, just to be sure, you're looking at the right template for an archive page?

  23. tshirtfiend
    Member
    Posted 4 years ago #

    Ha! No, I appreciate the comment re: the archive page. I created a "taxonomy-type.php" file, and checked that it is, indeed, being used on the page (echoed a string).

    When you say "above the endwhile", do you mean still in the main post loop? If that's the case, the link to "Older items" shows up, but clicking on it brings me to a 404 page.

    Also, this is what my loop looks like (in case that matters):

    query_posts( array( 'post_type' => 'portfolio', 'showposts' => 1 ) );
                if ( have_posts() ) : while ( have_posts() ) : the_post();
                	the_content();
                thematic_navigation_below();
                endwhile;
                endif;
  24. Rev. Voodoo
    Volunteer Moderator
    Posted 4 years ago #

    I need to pay attention to what people type a little more! lol

    on pages and single, the next_post_link is above the endwhile on my theme

    on posts pages, such as on my taxonomy page, the navigation is between the endwhile and endif

    Also, your query needs to include pagination, thats what we were talking about above

    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts(array(
    	'post_type' => 'portfolio', // custom post type
             'showposts' => 1,
             'paged'=>$paged,
            ));
    ?>
  25. tshirtfiend
    Member
    Posted 4 years ago #

    Here's what's happening:

    I get a link to "Older items", which seems good. That links to "SITEURL/TAXONOMY/TAXONOMY_TERM/page/2/" (caps=generic structure)

    When I click the link, I get the 404.

    My loop looks like:

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts(array(
    				'post_type' => 'portfolio', // custom post type
    				 'showposts' => 1,
    				 'paged'=>$paged,
    				));
                if ( have_posts() ) : while ( have_posts() ) : the_post();
                	the_content();
                endwhile;
                thematic_navigation_below();
                endif;

    Does it matter how I registered my CPT? They are not hierarchical.

  26. Rev. Voodoo
    Volunteer Moderator
    Posted 4 years ago #

    I had a few quirks with pagination at first when I set things up like you have

    resaved my functions.php

    I reset my permalinks (save to default, back to custom)

    and that fixed my problems. But your code looks good as does your structure... everything looks pretty much like mine

  27. tshirtfiend
    Member
    Posted 4 years ago #

    Bummer. Still not working.

    Oh well, thanks for the help! CPT could use a little more thorough documentation, if you ask me. I'll let you know if I get it working.

  28. Rev. Voodoo
    Volunteer Moderator
    Posted 4 years ago #

  29. tshirtfiend
    Member
    Posted 4 years ago #

    Ok, here's what I think is the crux of the issue:

    I have a menu that lists all of the terms of a taxonomy. If I click on the term name, I go to a page that is an archive of that term and lists all of the posts labeled with that term. There is no navigation, because I'm looking at an archive. If I click on a post's permalink, I go to the post's page (ie. single.php), and now have the Next and Prev links.

    What I don't know how to do is: click on the taxonomy term in the menu, and just have it display the first post labeled with that term, in a non-archive format. Essentially, it should use single.php instead of archive.php, or something to that effect.

    Does that make sense?

    (I've switched to Twentyten theme to test this, just editing functions.php to add the post types and taxonomies.)

  30. Rev. Voodoo
    Volunteer Moderator
    Posted 4 years ago #

    you said you are using taxonomy-type.php right? Thats exactly what I use. When I click on my term, it goes to an archive page of posts with that term, with pagination working properly, using the taxonomy-type.php file

    if you click on a term, you will always get an archive page....but with your query you should be able to get it to behave like a single.php type page

    As long as that taxonomy-term.php file has navigation in it , it should work

Topic Closed

This topic has been closed to new replies.

About this Topic