Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a question about usage of previous_posts_link/next_posts_link. Is it possible to use it for custom post types too?

I like to hear from you.

Thanks in advance. Casper

share|improve this question
    
Try it. What are your results? –  toscho Apr 1 '13 at 10:07
    
@toscho Notting is happening... –  Casper Apr 1 '13 at 10:30

3 Answers 3

This is the code that worked for me. I have a custom post type called "feature" defined like this:

$args = array(
    'label'               => 'feature',
    'description'         => 'Product feature pages',
    'labels'              => array(
        'name'                => 'Features',
        'singular_name'       => 'Feature',
        'menu_name'           => 'Feature',
        'parent_item_colon'   => 'Parent Feature:',
        'all_items'           => 'All Features',
        'view_item'           => 'View Feature',
        'add_new_item'        => 'Add New Feature',
        'add_new'             => 'New Feature',
        'edit_item'           => 'Edit Feature',
        'update_item'         => 'Update Feature',
        'search_items'        => 'Search Feature',
        'not_found'           => 'No Features found',
        'not_found_in_trash'  => 'No Features found in Trash',
    ),
    'supports'            => array( 'title', 'editor', 'excerpt', 'thumbnail', 'revisions', 'custom-fields', 'page-attributes', ),
    'taxonomies'          => array( 'category' ),
    'hierarchical'        => false,
    'public'              => true,
    'show_ui'             => true,
    'show_in_menu'        => true,
    'show_in_nav_menus'   => true,
    'show_in_admin_bar'   => true,
    'menu_position'       => 5,
    'menu_icon'           => '',
    'can_export'          => true,
    'has_archive'         => true,
    'exclude_from_search' => false,
    'publicly_queryable'  => true,
    'capability_type'     => 'feature',
);
register_post_type( 'feature', $args );

Then I create a file called single-feature.php in my theme folder, and inside that file I have:

<ul class="pager">
              <li class="previous">
                  <?php 
                  previous_post_link( '%link', '<span class="meta-nav">' . _x( '&larr;', 'Previous feature', 'mistcrm' ) . '</span> %title' ); ?>
              </li>
              <li class="next">
                <?php 
                  next_post_link( '%link', '%title <span class="meta-nav">' . _x( '&rarr;', 'Next feature', 'mistcrm' ) . '</span>' ); ?>
              </li>
            </ul>
share|improve this answer
    
Or if you didn't want to create a single-cpt.php file, you could simply hook in the links after the loop using the correct WordPress or theme specific hook and the conditional tag for your CPT. –  Brad Dalton Feb 8 at 8:58

I had used a plugin to create the custom post types and then found that none of the core functions would give me next / previous links to single custom posts.

I ended up writing a plugin that "seems" to work for me.

https://github.com/adampatterson/nextpost

Let me know if you have success of fail, it should give you next / previous links inside a single custom post, I don't think It will work in custom taxonomy but let me know :)

share|improve this answer

They do work.

Just make sure you include both of them INSIDE the loop. Otherwise it will never know what is previous/next.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.