How to edit next and previous post links (PHP problems)

Community Forums Forums Design Tips and Tricks How to edit next and previous post links (PHP problems)

This topic is: resolved

This topic contains 3 replies, has 3 voices, and was last updated by  samw 8 months, 1 week ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #94118

    cookieandkate
    Member
    Post count: 60

    Hi,

    I’ve searched all over the place and tried every code snippet I can find. I just want to edit my previous and next post links (which currently display the post titles) by adding “older post” and “newer post” labels above those titles.

    I’ve managed to add a whole new set of previous and next post links with the following code, but I just want one set (the original set) to display.

    `
    //* Add post navigation (requires HTML5 theme support)
    add_action( ‘genesis_entry_footer’, ‘genesis_prev_next_post_nav’ );

    //* Customize the next and previous links
    add_action(‘genesis_after_entry’, ‘next_previous_after_posts’, 5);
    function next_previous_after_posts() {
    if ( is_single() ) {
    ?>
    <div class=”adjacent-entry-pagination pagination”>
    <div class=”pagination-previous alignleft”>
    <?php previous_post(‘<div class=”custom”>&larrtl; newer post</div> %’, ”, ‘yes’); ?>
    </div><div class=”pagination-next alignright”>
    <?php next_post(‘<div class=”custom”>older post &rarrtl;</div> %’, ”, ‘yes’); ?>
    </div></div>
    <?php
    } }’

    I’ve tried deleting the “add_action(‘genesis_after_entry’,” line and changing next_previous_after_posts to genesis_prev_next_post_nav, but it kills my site. I’m clearly missing something.

    If you can help me with this issue, I would so appreciate it.

    Thank you,
    Kate

    #94154

    efuller
    Participant
    Post count: 59

    Kate:

    Please try replacing your code with the code below:

    [php]//* Add post navigation (requires HTML5 theme support)
    remove_action( ‘genesis_entry_footer’, ‘genesis_prev_next_post_nav’ );
    add_action( ‘genesis_entry_footer’, ‘cookie_prev_next_post_nav’ );

    function cookie_prev_next_post_nav() {
    if ( ! is_singular( ‘post’ ) )
    return;

    genesis_markup( array(
    ‘html5′ => ‘<div %s>’,
    ‘xhtml’ => ‘<div class="navigation">’,
    ‘context’ => ‘adjacent-entry-pagination’,
    ) );

    echo ‘<div class="pagination-previous alignleft">';
    previous_post_link(‘%link’, ‘Older Post’);
    echo ‘</div>';

    echo ‘<div class="pagination-next alignright">';
    next_post_link(‘%link’, ‘Newer Post’);
    echo ‘</div>';

    echo ‘</div>';
    }[/php]

    You should be able to replace the ‘Older/Newer Post’ text with anything you would like.

    Thanks,

    Eric


    I am a web developer

    #94162

    cookieandkate
    Member
    Post count: 60

    THANK YOU! Thank you so much. Your code worked great. I modified it slightly to return the post titles instead of “Older Post”/”Newer Post” labels. I also switched the previous_post_link and next_post_link so the older posts link (on the posts) is on the same side as my older pages link (on the pages). I also added divs.

    Final result: http://i.imgur.com/VfHXRPh.png

    Final code: `//* Add post navigation (requires HTML5 theme support)
    remove_action( ‘genesis_entry_footer’, ‘genesis_prev_next_post_nav’ );
    add_action( ‘genesis_entry_footer’, ‘cookie_prev_next_post_nav’ );

    function cookie_prev_next_post_nav() {
    if ( ! is_singular( ‘post’ ) )
    return;

    genesis_markup( array(
    ‘html5′ => ‘<div %s>’,
    ‘xhtml’ => ‘<div class=”navigation”>’,
    ‘context’ => ‘adjacent-entry-pagination’,
    ) );

    echo ‘<div class=”pagination-previous alignleft”>';
    next_post_link(‘%link’, ‘<div class=”custom”>&larrtl; newer post</div> %title’);
    echo ‘</div>';

    echo ‘<div class=”pagination-next alignright”>';
    previous_post_link(‘%link’, ‘<div class=”custom”>older post &rarrtl;</div> %title’);
    echo ‘</div>';

    echo ‘</div>';
    }

    Thanks again!
    Kate

    #95764

    samw
    Participant
    Post count: 55

    Hi

    Wonder if you can help, tired to follow both your codes to add next and previous post links to Eleven Twenty Pro that display post titles..I cant seem to get this to work..

    Also, is there a way in Genesis to get the post title to display as a permalink. Many Thanks

    (Topic opened as below)
    Hi

    I am trying to edit the post navigation links in Eleven Twenty Pro to display the post title.

    Where is the place to edit this – cant find anything in functions.php or do I need to add a new function?

    Tried adding this to functions.php to test if its the right code but as no changes appeared in the link text, i guess not?

    //* Add post navigation (requires HTML5 theme support)
    remove_action( ‘genesis_entry_footer’, ‘genesis_prev_next_post_nav’ );
    add_action( ‘genesis_entry_footer’, ‘cookie_prev_next_post_nav’ );

    function cookie_prev_next_post_nav() {
    if ( ! is_singular( ‘post’ ) )
    return;

    genesis_markup( array(
    ‘html5′ => ‘<div %s>’,
    ‘xhtml’ => ‘<div class=”navigation”>’,
    ‘context’ => ‘adjacent-entry-pagination’,
    ) );

    echo ‘<div class=”pagination-previous alignleft”>’;
    previous_post_link(‘%link’, ‘new text1′);
    echo ‘</div>’;

    echo ‘<div class=”pagination-next alignright”>’;
    next_post_link(‘%link’, ‘new test 2′);
    echo ‘</div>’;

    echo ‘</div>’;
    }


    SEO & Online Marketing Consultant

    Metta3 | G+ | LinkedIn

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.