Problem: I would like to include pagination on my single post pages that allows a user to navigate between posts that are children of the same parent post.
Solution:
FOR AN UPDATED SOLUTION WITH RELATIONSHIPS IN TYPES 3.0+: https://toolset.com/forums/topic/next-and-previous-sibling-posts-in-a-one-to-many-post-relationship/
Legacy Relationships: Add a pagination shortcode that will output the next and previous links based on the parent and child post types:
// Add Pagination Shortcode function pagination() { $next_post = wpv_child(1, 'exhibition', 'painting'); $previous_post = wpv_child(-1, 'exhibition', 'painting'); $prev_pagination= ''; $next_pagination = ''; if($previous_post ){ $prev_pagination = "<div class='navigation'><div class='previousnav'> <a href='".get_permalink($previous_post->ID)."'> << ".get_the_title($previous_post->ID)."</a></div>"; } if($next_post){ $next_pagination = "<div class='nextnav'><a href='".get_permalink($next_post->ID)."'> ".get_the_title($next_post->ID).">></a></div>"; } $pagination = "<div class='currentexb'><a href='http://www.neilpinkett.co.uk/npwp/exhibition/''>GALLERY</a> >".get_the_title()."</div>"; return $prev_pagination.$pagination.$next_pagination; } add_shortcode( 'pagination', 'pagination' ); function wpv_child($step, $parentslug, $childslug) { global $post; $parent = get_post_meta($post->ID, '_wpcf_belongs_' . $parentslug . '_id', true); $children = get_posts(array('post_type' => $childslug, 'meta_key' => '_wpcf_belongs_' . $parentslug . '_id', 'meta_value' => $parent, 'numberposts' => -1)); $i = 0; foreach ($children as $i => $child) { if ($child->ID == $post->ID) break; } $i += $step; if (isset($children[$i])) return $children[$i]; }
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | - | - |
13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | - | - |
Supporter timezone: America/New_York (GMT-04:00)
This topic contains 9 replies, has 3 voices.
Last updated by 7 years, 1 month ago.
Assisted by: Christian Cox.