• Hello –

    I am attempting to do something that seems as though it would be quite simple. I have found questions elsewhere that are similar but are not exactly what I wish to do.

    Essentially, on my single.php page I have implemented a Next / Previous bar bellow each post that takes the viewer to the previous post published or to the next post published.

    I’ve run into trouble pertaining to the latest published post, where the “Next” button still partially loads. Here is my code:

    <div class="pagination clearfix cew_buttonbox">
            <table class="cew_prevnextbox3">
    		<tr>
    		<td style="float:left"><div class="cew_button"><?php previous_post_link('%link', '< Older Post') ?></div></td>
    
    		<td style="float:right"><div class="cew_button"><?php next_post_link('%link', 'Newer Post >') ?></div></td>
    
    		</tr>
    		</table>
        </div>

    The generated link to the “next” post does not generate — as desired and expected — because there isn’t a next post. The “previous” link generates just fine. But my div (class=”cew_button”) still loads exactly as I have it styled in CSS, sans the link.

    Is there a way to condition that “next” div to NOT appear on the first post’s page? The problem is similar for my oldest published post, in which the “previous” box appears sans the link.

Viewing 3 replies - 1 through 3 (of 3 total)
  • maybe you can extract the essential conditional statement from this article: https://www.transformationpowertools.com/wordpress/advanced-styling-of-the-prev-next-post-links

    in principle:

    <?php if(get_adjacent_post(false, '', true)) { /*normal prev link incl html*/ }
    else { /*special if at the end of posts*/ } ; ?>
    
    <?php if(get_adjacent_post(false, '', false)) { /*normal next link incl html*/ }
    else { /*special if at the start of posts*/ } ; ?>
    Thread Starter boydigital

    (@boydigital)

    Very interesting. Thank you alchymyth.

    I believe there is a solution in there somewhere. I will play with this tonight and report back on my success or failure soon.

    Thread Starter boydigital

    (@boydigital)

    Once again, thank you alchymyth for providing the information.

    With some creative liberties to the code at the link supplied above, I found a recipe that works. I’ve attached my solution below. The most difficult aspect was finding how to have the link actually show up within my <div>.

    Case solved.

    <div class="pagination clearfix cew_buttonbox">
            <table class="cew_prevnextbox3">
    		<tr>
    		<td style="float:left"><?php if(get_adjacent_post(false, '', true)) { echo previous_post_link('%link', '<div class="cew_button">< Older Post</div>'); }
    else { echo '&nbsp;'; } ; ?>
    </td>
    		<td style="float:right"><?php if(get_adjacent_post(false, '', false)) { echo next_post_link('%link', '<div class="cew_button">Newer Post ></div>'); }
    else { echo '&nbsp;'; } ; ?>
    </td>
    		</tr>
    		</table>
        </div>
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘apply different formatting to the first post's page’ is closed to new replies.