Hi,
Thank you for contacting us and I'd be happy to assist.
To achieve this, you'll need a new custom shortcode that can show the first or the last post's navigation link, as needed:
add_shortcode( 'first_last_post', 'first_last_shortcode' );
function first_last_shortcode($atts) {
$a = shortcode_atts( array(
'post_type' => '',
'type' => '',
), $atts );
if( $a['type'] == 'first' ) {
$order = 'ASC';
} elseif ( $a['type'] == 'last' ) {
$order = 'DESC';
}
if( (!empty($a['post_type'])) && (!empty($a['type'])) ) {
$args = array(
'posts_per_page' => 1,
'post_type' => $a['post_type'],
'post_status' => 'publish',
'orderby' => 'menu_order',
'order' => $order,
);
$posts_array = get_posts( $args );
if(!empty($posts_array)) {
}
ob_start();
echo '<span class="nav-'.$a['type'].'"><a href="'.get_the_permalink($posts_array[0]->ID).'" rel="'.$a['type'].'">'.get_the_title($posts_array[0]->ID).'</a> : '.ucfirst($a['type']).'</span>';
$result = ob_get_contents();
ob_end_clean();
return $result;
}
}
The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.
Next, please add "first_last_post" in the "Third-party shortcode arguments" section, at WP Admin -> Toolset -> Settings -> Front-end Content.
This shortcode can be used to show the first or the last post links, like this:
// First post link where post type is 'portfolio'
[first_last_post type="first" post_type="portfolio"]
// Last post link where post type is 'portfolio'
[first_last_post type="last" post_type="portfolio"]<br>
And in your content template, you can show these shortcodes within the conditional statements, so that when the next and previous post links are empty, the output from this new first/last post link is used:
[wpv-conditional if="( '[prev_post]' eq '' )"]
[first_last_post type="last" post_type="portfolio"]
[/wpv-conditional]
[wpv-conditional if="( '[prev_post]' ne '' )"]
[prev_post]
[/wpv-conditional]
[wpv-conditional if="( '[next_post]' eq '' )"]
[first_last_post type="first" post_type="portfolio"]
[/wpv-conditional]
[wpv-conditional if="( '[next_post]' ne '' )"]
[next_post]
[/wpv-conditional]
I hope this helps and please let me know if you need further assistance.
regards,
Waqar