Views is a WordPress plugin that lets you easily display content on your website's front-end in any way you choose.
Views User Guides include detailed documentation for creating lists of content, templates for content and archive page and also explain how to create parametric searches for any content type.
When you ask for help or report issues, make sure to tell us the versions of the Toolset plugins that you have installed and activated.
Viewing 15 topics - 2,536 through 2,550 (of 3,151 total)
Problem: I have a one-to-many post relationship between two custom post types. In the template for the child post type, I would like to display "Next" and "Previous" links to paginate between the sibling posts.
Solution: Use a custom shortcode like this example that implements the post relationships API to create pagination links:
// https://toolset.com/forums/topic/next-and-previous-sibling-posts-in-a-one-to-many-post-relationship/
// get a link to the next or previous sibling post in child post content template
// example: [tssupp-next-prev-child current="[wpv-post-id]" step="1" relslug="book-chapter"][/tssupp-next-prev-child]
// current: current post id, step: 1 for next or -1 for previous, relslug: slug of the post relationship
function tssupp_next_prev_child($atts) {
$a = shortcode_atts( array(
'current' => 0,
'step' => '1',
'relslug' => '',
), $atts );
$link = '';
// get all child posts
$relationship_slug = $a['relslug'];
$current_child_id = $a['current'];
$parent_id = toolset_get_related_post( $current_child_id, $relationship_slug );
$sibling_args = array(
'query_by_role'=>'parent',
'limit'=>1000,
'role_to_return'=>'child',
'orderby'=>'title'
);
$siblings = toolset_get_related_posts( $parent_id, $relationship_slug, $sibling_args );
// loop over child posts and get index of the current post
foreach($siblings as $i=>$sibling) {
if( $sibling == $current_child_id ) {
break;
}
}
// increment or decrement index for next or previous sibling
$i += $a['step'];
// create link to next/previous sibling
if(isset($siblings[$i])){
$perm = get_the_permalink( $siblings[$i] );
$title = get_the_title( $siblings[$i] );
$link .= $a['step']=='1' ? "Next: " : "Previous: ";
$link .= "<a href='" . $perm . "'>" . $title . "</a>";
}
// output the link, or empty string if not set
return $link;
}
add_shortcode( 'tssupp-next-prev-child', 'tssupp_next_prev_child' );
You'll use the shortcode like this to generate a "Next" link (if necessary):