• What I have:

    <?php $prev_post = get_previous_post(); if($prev_post) { ?><div class='prev'><p><?php previous_post_link('%link') ?></p></div><?php }?>
    <?php $next_post = get_next_post(); if($next_post) { ?><div class='next'><p><?php  next_post_link('%link') ?></p></div><?php }?>

    I need previous post to be replaced by “HOME” if not available. For example, on the very first post, the previous link does not show because there are no previous articles, just the index page.

Viewing 1 replies (of 1 total)
  • Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Maybe because you have your PHP on one line, you can’t see where you can put your else.
    Do something like:

    <?php
    $prev_post = get_previous_post(); 
    
    if($prev_post) {
    ?>
        <div class='prev'><p><?php previous_post_link('%link') ?></p></div>
    <?php
    } else {
       [...]
    }

Viewing 1 replies (of 1 total)
  • The topic ‘prev/next Posts, else if prev is not available?’ is closed to new replies.