[resolved] Separate Next/Previous page links? (6 posts)

  1. ChimpanzeeUK
    Posted 4 years ago #

    Sorry if I'm being a bit dense here but this seems like it should be so obvious and I can't figure it out! :)

    At the bottom of my archive page, I have links to 'Older Posts' and 'Newer Posts'. It's pretty simple:

    <div class="pageNav">
    <div class="navLeft"><?php next_posts_link('Older Entries', '0') ?></div>
    <div class="navRight"><?php previous_posts_link('Newer Entries', '0'); ?></div>

    My navLeft and navRight classes float left and right respectively and each have their own arrow-style background image in CSS. I want to do something similar for navigation in multi-page posts but I can't find a function that will allow me to do it.

    wp_link_pages has various options but will always, it seems, print the 'Page 1', 'Page 2', 'Page 3', etc. or 'Next Page' and 'Previous Page' links in the same block. There doesn't seem to be any way to separate them.

    I essentially need previous_page_link and next_page_link functions which work in the same way as posts navigation but no such function seems to exist. I'm surprised these two functions work so differently.

    Any help would be greatly appreciated.

  2. Chip Bennett
    Theme Review Admin
    Posted 4 years ago #

    You should have everything you need, with the arguments available for wp_link_pages():

    <?php $args = array(
        'before'           => '<p>' . __('Pages:'),
        'after'            => '</p>',
        'link_before'      => ,
        'link_after'       => ,
        'next_or_number'   => 'number',
        'nextpagelink'     => __('Next page'),
        'previouspagelink' => __('Previous page'),
        'pagelink'         => '%',
        'more_file'        => ,
        'echo'             => 1 ); ?>

    You want to set:
    - next_or_number to next
    - link_before to <span class="pagelink">
    - link_after to </span>

    Such as:

    <?php wp_link_pages( 'next_or_number=next&link_before=<span class="pagelink">&link_after=</span>' ); ?>

    Then, you just need to style span.pagelink accordingly, e.g.:

    span.pagelink {
         width: 50%;

    (or however you would like)

  3. ChimpanzeeUK
    Posted 4 years ago #

    Thanks for replying Chip. The problem is that the link_before and link_after need to be different for the 'Next' and 'Previous' links (because the background image points in a certain direction) but the function uses the same string for each link.

    Since my first post, I'm managed to cobble together a partial solution by just calling the function twice. It's not very elegant but...


    The problem with that is that it echos the 'before' and 'after' for both, leaving empty DIVs with the background image still there. I'm wondering now if there's an 'if' I can wrap around each one to only call the first one when I'm NOT on the first page and only do the second one if I'm NOT on the last page. Does that make sense? Any ideas on how I could do that... or a better workaround completely?! :)

  4. Chip Bennett
    Theme Review Admin
    Posted 4 years ago #

    You can make use of the $paged variable.

    Apologies, but I'll have to come back later to post code examples.

  5. ChimpanzeeUK
    Posted 4 years ago #

    Ok, I've created a really overblown workaround. I'm sure there are better solutions but I'm to the point of not caring now! At least this works!


    Thanks for your efforts, Chip.

  6. Chip Bennett
    Theme Review Admin
    Posted 4 years ago #

    Sometimes, as long as it works, that's all that matters. :)

    Glad you figured something out!

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.