0

When on the first page of blog wordpress shows only "older posts" link because there are no newer posts, but i would like to show also the "newer posts" link but style it as inactive.

i need to do the same thing with page navigation and with single posts navigation.

Thanks

2
  • what is the code of these links at the moment?
    – Michael
    Commented Dec 17, 2011 at 14:53
  • currently the code is: <?php if (show_posts_nav()) : ?> <nav class="page_navi"> <ul> <li class="newer_link"><?php previous_posts_link('Newer posts'); ?></li> <li class="older_link"><?php next_posts_link('Older posts'); ?></li> </ul> </nav> <?php endif; ?>
    – Mikk Olli
    Commented Dec 17, 2011 at 18:08

1 Answer 1

1

If you check the code for previous_posts_link function in link-template.php file i.e.

function previous_posts_link( $label = null ) {
   echo get_previous_posts_link( $label );
}
// get_previous_posts_link
function get_previous_posts_link( $label = null ) {
  global $paged;
  if ( null === $label )
     $label = __( '&laquo; Previous Page' );
        if ( !is_single() && $paged > 1 ) {
           $attr = apply_filters( 'previous_posts_link_attributes', '' );
           return '<a href="' . previous_posts( false ) . "\" $attr>". preg_replace( '/&([^#])(?![a-z]{1,8};)/', '&#038;$1', $label ) .'</a>';
        }
}

you can clearly see that the condition is set for page > 1, means on page one it will not show the link. For this you can use PageNavi plugin or you can dig into the code to override the default behavior. One more suggestion, don't alter the core files as you will loose this functionality when you will upgrade WP.

Your Answer

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

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