0

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;
}
2
  • 1
    Can't you just use css for this? Do you want to add a space between 3(last page) and Next page ? Jan 8, 2013 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, 2013 at 16:54

1 Answer 1

1

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;
}
1
  • ^ I can't even express how much frustration you just curbed, you are the man. Jan 8, 2013 at 17:16

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.