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 can't for the life of me get this to work - this is the code in my single-osu_work.php file which is used for this post type, but I can't get the next and previous post links to appear - can you see a problem? I've tried putting the pagination links within the loop but still nothing.

Thanks,

Osu

if (have_posts()) : while (have_posts()) : the_post(); ?>
    <article <?php post_class(); ?> id="post-<?php the_ID(); ?>">
        <h1 id="mainheading"><?php the_title(); ?></h1>
        <?php the_content(); ?>
        <footer class="postmetadata">Date: <?php the_date('Y'); ?></footer>
    </article>
    <?php endwhile;
else : ?>
    <article id="nada">
        <h2 id="mainheading">Nothing found</h2>
        <p>Apologies, but you've come across a page that can't be found.</p>
        <p>Please use the search function or continue browsing.</p>
        <?php echo get_search_form(); ?>
    </article>  
<?php endif; ?>

    <div class="next-posts"><?php next_post_link('%link', 'Newer entry &gt;', true) ?></div>
    <div class="prev-posts"><?php previous_post_link('%link', '&lt; Older entry', true) ?></div>
    <div class="clear">&nbsp;</div>
share|improve this question
1  
They should be inside the loop - you might want to update your code. –  vancoder Aug 16 '13 at 16:40
    
Unfortunately, I already tried that and it doesn't work, the navigation links don't appear, only the div markup around them... –  Osu Aug 18 '13 at 9:29
    
Update: I can get this to work if I move it into the loop but only use next_post_link() not next_post_link('%link', 'Newer entry &gt;', true) - any idea why that might be? Is it because it's a custom post type and you can't rename post pagination links? I'd like to rename the link if at all possible. Thanks –  Osu Aug 18 '13 at 9:33
add comment

1 Answer 1

up vote 0 down vote accepted

Ok, I found the solution in terms of getting the links to appear, however, I needed to remove the 'true' argument for only moving between posts in the same category/taxonomy.

Is that right that you can't restrict the posts linked to so that they're only the ones within the same taxonomy? Here's the correct code and as vancoder says, it needs to appear within the loop (I placed this just before endwhile;):

<div class="next-posts"><?php next_post_link('%link', 'Newer entry &gt;') ?></div>
<div class="prev-posts"><?php previous_post_link('%link', '&lt; Older entry') ?></div>

As this is a custom post type with a custom taxonomy, I assume the pagination is breaking because Wordpress is looking for a 'category' as if these were normal posts? Is there any way to make this work so that only Work posts within my custom taxonomy are returned?

share|improve this answer
    
Yes, the functions only work with the 'category' taxonomy. I'm not aware of a method of over-riding this. –  vancoder Aug 19 '13 at 6:22
    
Ok, thanks for your help Vancoder –  Osu Aug 19 '13 at 7:05
add comment

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.