Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

This question has been a pain in my side for the last few days.

I am using a function to display page numbers and next/previous links with WP_LINK_PAGES. The code I'm using (below) is a shortened version of the code found here - to the best of my knowledge, it is correct. (Go easy on me, just diving into PHP.)

Please view the working example here.

The problem should be a simple fix, but I can't figure it out. I would like to add a space in front of the "Next Page" link which is not linked itself to the next page in order for the pagination to have equal spacing.

function wp_link_pages_args_prevnext_add($args)
{
    global $page, $numpages, $more, $pagenow;

    if($page-1) # there is a previous page
        $args['before'] .= _wp_link_page($page-1)
            . $args['link_before']. $args['previouspagelink'] . $args['link_after'] . '</a>'
        ;

    if ($page<$numpages) # there is a next page
        $args['after'] = _wp_link_page($page+1)
            . $args['link_before'] . $args['nextpagelink'] . $args['link_after'] . '</a>'
        ;

    return $args;
}
share|improve this question
1  
Can't you just use css for this? Do you want to add a space between 3(last page) and Next page ? –  Pontus Abrahamsson Jan 8 '13 at 16:45
    
Agreed, you should be using CSS to do this, probably margin, rather than hard-coding the space. –  s_ha_dum Jan 8 '13 at 16:54
add comment

1 Answer

up vote 1 down vote accepted

In my opinion CSS isn't the right way, it should be a "real" space. Also there is no class to target the differents links in the string.

Try this code:

    function wp_link_pages_args_prevnext_add($args)
{
    global $page, $numpages, $more, $pagenow;

    if($page-1) # there is a previous page
        $args['before'] .= ' '. _wp_link_page($page-1) 
            . $args['link_before'] . $args['previouspagelink']  . '</a>' . ' '
        ;

    if ($page<$numpages) # there is a next page
        $args['after'] = ' '. _wp_link_page($page+1)
           . $args['link_before'] . $args['nextpagelink']  . '</a>'
            . $args['after'] 
        ;

    return $args;
}
share|improve this answer
    
^ I can't even express how much frustration you just curbed, you are the man. –  AndrettiMilas Jan 8 '13 at 17:16
    
you are welcome! –  molokom Jan 8 '13 at 17:23
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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