• Resolved kortaben

    (@kortaben)


    Hi,
    I’m building a website containing a fair amount of posts in different categories.
    I’m using a previous & next post button using the post_link function.
    Browsing through the posts it all works as it should but when I reach the last post of that category the button disappears (which normally is a good thing) but I want the button to turn into a button that takes you back to the category overview.

    The permalinks are setup like this
    localhost/work/2012/postname
    localhost/work/2012/postname2
    localhost/work/2012/postname3
    etc..

    So reaching the last post in the cateogry 2012 should give me a link back to
    localhost/work/2012

    The code I have right now looks like this:

    <?php
    previous_post_link('%link', '<div class="arrow-left"></div>', TRUE);
    if (empty( $previous_post_link )): ?>
      <a href="<?php echo esc_url( $category_link ); ?>"><div class="arrow-left"></div></a>
    <?php endif;
    ?>

    Does anyone have an idea?

    Thanks!

    Regards
    Marcus

Viewing 1 replies (of 1 total)
  • Thread Starter kortaben

    (@kortaben)

    I figured it out. Here’s the finished code

    <?php if
    	(get_adjacent_post(true, '', true)) { 
    
        }
        else {
    		next_post_link('%link', '<div class="arrow-right"></div>', TRUE);    }
      ?>
    </li>
    <li>
    <?php if
    	(get_adjacent_post(true, '', true)) {
            previous_post_link('%link', '<div class="arrow-left"></div>', TRUE);
        }
        else {
            echo '<a href="../"><div class="arrow-left"></div></a>';
        }
      ?>

Viewing 1 replies (of 1 total)
  • The topic ‘Conditional next_ & previous_post_link’ is closed to new replies.