0

I created a category and call it "Blog". Then I created some posts and assign "Blog" as category for the posts. So I'm trying to go to previous/next into the same category and doesn't work. Here is my code:

<nav id="nav-single">
    <span class="nav-previous"><?php previous_post_link('%link', __('<span class="meta-nav">&larr;</span> Previous'), TRUE); ?></span>
    <span class="nav-next"><?php next_post_link('%link', __('Next <span class="meta-nav">&rarr;</span>'), TRUE); ?></span>
</nav><!-- #nav-single -->

None of the links is being displayed even if I have more than one post created. If I remove the TRUE value then it goes to other categories. What am I doing wrong?

3 Answers 3

1

This is the default in WordPress Twenty Eleven Theme

<nav id="nav-single">
        <h3 class="assistive-text"><?php _e( 'Post navigation', 'twentyeleven' ); ?></h3>
        <span class="nav-previous"><?php previous_post_link( '%link', __( '<span class="meta-nav">&larr;</span> Previous', 'twentyeleven' ) ); ?></span>
        <span class="nav-next"><?php next_post_link( '%link', __( 'Next <span class="meta-nav">&rarr;</span>', 'twentyeleven' ) ); ?></span>
</nav><!-- #nav-single -->

I copy pasted your code to replace the above default code.

<nav id="nav-single">
    <span class="nav-previous"><?php previous_post_link('%link', __('<span class="meta-nav">&larr;</span> Previous'), TRUE); ?></span>
    <span class="nav-next"><?php next_post_link('%link', __('Next <span class="meta-nav">&rarr;</span>'), TRUE); ?></span>
</nav><!-- #nav-single -->

Your code is working perfectly on my system. Your code doesn't have any problem. You can refer to Codex for changing your code further.

http://codex.wordpress.org/Function_Reference/previous_post_link

0

This worked for me:

<div id="nav-single">           
<div class="nav-previous"><?php previous_post_link('&#8249; %link', '%title', 'Next post in category', TRUE); ?> </div>
<div class="nav-next"><?php next_post_link('%link &#8250;', '%title', 'Next post in category', TRUE); ?> </div>         
</div><!-- end of #nav-single -->'
0

I had the same problem, and I found, after reading well the codex, that my post type had a custom taxonomy, not named "category" (default to WP), but "categories", so to be functional here the code I had to write:

<?php previous_post_link('%link', '<i title="Previous Project" class="prev"></i>', true, array(), 'categories') ?>
<?php next_post_link('%link', '<i title="Next Project" class="prev"></i>', true, array(), 'categories') ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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