navigation - Wordpress show next 3 x number adjacent custom posts from existing -
on single/detail custom post page display custom nav of li's or divs in sidebar displays both title, excerpt , permalink next 3 posts within custom post series. if on custom post 3 show 4, 5, 6 in sidebar.
the closest i've found :-=
global $post; $current_post = $post; // remember current post for($i = 1; $i <= 3; $i++){ $post = get_previous_post(); // uses $post->id setup_postdata($post); // stuff here the_title(); } $post = $current_post; // restore
problem shows first next post , need show 3.
thanks glennyboy
your code above close. looks you're missing endfor;
, maybe bit of html. try blow code:
<ul> <?php global $post; $current_post = $post; for($i = 1; $i <= 3; $i++): $post = get_previous_post(); setup_postdata($post); echo '<li>'; echo '<h3>' . get_the_title() . '</h3>'; the_excerpt(); echo get_post_meta($post->id, 'your_metafield_name', true); echo '</li>'; endfor; $post = $current_post; ?> </ul>
when using the_excerpt()
should include "read more" link post, won't need use the_permalink()
function. if don't have 3 or more previous posts, show how many previous posts there are. tested in single.php template file, should work in custom post type single template file if using custom one. let me know if have questions.
Comments
Post a Comment