Support » Fixing WordPress » next_posts_link greyed out if null

  • I want to have my next_posts_link and previous_posts_link show greyed-out text instead of a link when someone views the first or last page and there are no more (when the value is assumably null).

    I know nothing about PHP or non-html wordpress code beyond extreme basics(if is_page – else – endif).

Viewing 5 replies - 1 through 5 (of 5 total)
  • This is the section in link-template.php but I just don’t know how to accomplish this. I appreciate any help anyone has to offer.

    function next_posts_link($label='Next Page »', $max_page=0) {
    	global $paged, $wpdb, $wp_query;
    	if ( !$max_page ) {
    		$max_page = $wp_query->max_num_pages;
    	if ( !$paged )
    		$paged = 1;
    	$nextpage = intval($paged) + 1;
    	if ( (! is_single()) && (empty($paged) || $nextpage <= $max_page) ) {
    		echo '<a href="';
    		echo '">'. preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $label) .'</a>';

    Does anyone know how to do this? I need this to complete my theme. I’m using a bar that has the previous and next links seperated on the left and right. It looks lopsided when people enter and there is only text for previous link.

    Can anyone help me do this?

    Is this not possible? I’m open to CSS formating tricks if any exist that would allow for blank text but overwritten with the link if one exists. I have no clue how to go about this but it may be possible.

    you can do this using the global parameter $paged and the query $wp_query->max_num_pages;
    it’s a bit of a long winded hack and i’m sure there’s a simpler way, but this is the way i found when faced with a similar problem:

    //set the divider that separates the links
    $divider = ' | ';
    //get the current page number
    $page_num = $paged;
    if($page_num == ''){$page_num = '1';}
    //get the number of the last page
    $max_num_pages = $wp_query->max_num_pages;
    //if its the first page
    posts_nav_link('','', __('previous posts'));
    echo $divider;
    echo'<span class="greyed_out">next posts</span>';
    //if its in the middle
    if($page_num>1 && $page_num<$max_num_pages){
    posts_nav_link('','', __('previous posts'));
    echo $divider;
    posts_nav_link('', __('next posts'),'');
    //if its the last page
    if($page_num == $max_num_pages){
    echo'<span class="greyed_out">previous posts</span>';
    echo $divider;
    posts_nav_link('', __('next posts'),'');
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘next_posts_link greyed out if null’ is closed to new replies.