Community Forums › Forums › Archived Forums › Design Tips and Tricks › How to edit next and previous post links (PHP problems)
Tagged: Magazine Pro, next post, pagination
- This topic has 3 replies, 3 voices, and was last updated 10 years, 6 months ago by samw.
-
AuthorPosts
-
March 9, 2014 at 10:34 pm #94118cookieandkateMember
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">↢ newer post</div> %', '', 'yes'); ?>
</div><div class="pagination-next alignright">
<?php next_post('<div class="custom">older post ↣</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,
KateMarch 10, 2014 at 6:57 am #94154efullerMemberKate:
Please try replacing your code with the code below:
//* 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>'; }
You should be able to replace the 'Older/Newer Post' text with anything you would like.
Thanks,
Eric
I am a web developer
March 10, 2014 at 9:14 am #94162cookieandkateMemberTHANK 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">↢ newer post</div> %title');
echo '</div>';echo '<div class="pagination-next alignright">';
previous_post_link('%link', '<div class="custom">older post ↣</div> %title');
echo '</div>';echo '</div>';
}
'Thanks again!
KateMarch 20, 2014 at 12:43 am #95764samwMemberHi
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)
HiI 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>’;
}
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.