Community Forums › Forums › General Genesis Framework Discussions › Reverse/swap post navigation in single post
- This topic has 6 replies, 2 voices, and was last updated 1 year, 12 months ago by tkwingwing.
-
AuthorPosts
-
May 10, 2022 at 11:19 pm #505219tkwingwingParticipant
I'd like to swap the next/previous navigation buttons on a single post page so when clicking the 'next post' button on the right it navigates to an older post.
I mean to swap the chronological order, I think it would be to just swap their positions. So it's currently: On the left side "<- [Post Title] (which is an older post)" and on the right side "[Post Title] (which is a newer post) ->".
I'd like it to be on the left side "<- [Post Title] (which is a newer post)" and on the ride side "[Post Title] (which is an older post) ->".
How can I make it? thanks
https://www.kennethtse.net/interior-design-for-a-residential-apartment-in-grand-central-2022/May 10, 2022 at 11:26 pm #505220Brad DaltonParticipantYou can modify the genesis_adjacent_entry_nav function from Genesis. Copy it to your child theme and change the functions for each link.
May 11, 2022 at 12:08 am #505221tkwingwingParticipanthi, Thanks for the reply,
I am new to Genesis and have no idea about coding, would you mind giving me more hints or samples to follow? Much appreciate. thanks
May 11, 2022 at 1:03 am #505222Brad DaltonParticipantHappy to point you in the right direction.
Please search for the function in your genesis folder and copy the entire function to your child theme.
You'll need a basic understanding of PHP code to remove the default function, add a new custom function and complete the modification.
May 11, 2022 at 2:05 am #505223tkwingwingParticipantI only found the genesis_adjacent_entry_nav function in post.php.
However, when I copied the following code to the child theme's functions.php, it has no effect on my website.
--------------------------------
remove_action( 'genesis_after_entry', 'genesis_adjacent_entry_nav' );add_action( 'genesis_after_entry', 'genesis_adjacent_entry_nav2' );
function genesis_adjacent_entry_nav2() {
if ( ! is_singular() || ! post_type_supports( get_post_type(), 'genesis-adjacent-entry-nav2' ) ) {
return;
}genesis_markup(
[
'open' => '<div %s>',
'context' => 'adjacent-entry-pagination',
]
);$next_post_text = '<span class="adjacent-post-link">%title </span>';
if ( genesis_a11y() ) {
$next_post_text = '<span class="screen-reader-text">' . esc_html__( 'Next Post:', 'genesis' ) . ' </span>' . $next_post_text;
}
genesis_markup(
[
'open' => '<div %s>',
'context' => 'pagination-next',
'content' => get_next_post_link( '%link', $next_post_text ),
'close' => '</div>',
]
);$previous_post_text = '<span class="adjacent-post-link"> %title</span>';
if ( genesis_a11y() ) {
$previous_post_text = '<span class="screen-reader-text">' . esc_html__( 'Previous Post:', 'genesis' ) . ' </span>' . $previous_post_text;
}
genesis_markup(
[
'open' => '<div %s>',
'context' => 'pagination-previous',
'content' => get_previous_post_link( '%link', $previous_post_text ),
'close' => '</div>',
]
);genesis_markup(
[
'close' => '</div>',
'context' => 'adjacent-entry-pagination',
]
);}
/**
* Helper function to display adjacent entry navigation on single posts. Must be hooked togenesis_after_entry
at priority 10 or earlier to work properly.
*
* @since 1.5.1
*/
function genesis_prev_next_post_nav2() {add_post_type_support( 'post', 'genesis-adjacent-entry-nav2' );
}
May 11, 2022 at 2:10 am #505224Brad DaltonParticipantThat's a step in the right direction. Now you need to spend some time and work out why.
Good start.
May 11, 2022 at 2:20 am #505227tkwingwingParticipantI think the "remove_action( 'genesis_after_entry', 'genesis_adjacent_entry_nav' );"
is not really removing the default action, but what is the right way to remove it?
It is hard to find the solution...
-
AuthorPosts
- You must be logged in to reply to this topic.