Created
May 5, 2019 16:16
-
-
Save generatepress/179434f97888af190ee1d65e36402962 to your computer and use it in GitHub Desktop.
Make Dispatch Custom Post Navigation work with any custom post type
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="post-nav"> | |
<?php global $post; | |
$prevPost = get_previous_post(false); | |
$post_type = get_post_type(); | |
if($prevPost) { | |
$args = array( | |
'posts_per_page' => 1, | |
'include' => $prevPost->ID, | |
'post_type' => $post_type, | |
); | |
$prevPost = get_posts($args); | |
foreach ($prevPost as $post) { | |
setup_postdata($post); | |
?> | |
<a class="post-previous" href="<?php the_permalink(); ?>"> | |
<div class="post-nav-wrap" style="background: linear-gradient(0deg,rgba(52,62,71,0.1),rgba(52,62,71,0.3)),url('<?php the_post_thumbnail_url(); ?>');"> | |
<div class="post-nav">Previous</div> | |
<h3 class="post-nav-title"><?php the_title(); ?></h3> | |
</div></a> | |
<?php | |
wp_reset_postdata(); | |
} //end foreach | |
} // end if | |
$nextPost = get_next_post(false); | |
if($nextPost) { | |
$args = array( | |
'posts_per_page' => 1, | |
'include' => $nextPost->ID, | |
'post_type' => $post_type, | |
); | |
$nextPost = get_posts($args); | |
foreach ($nextPost as $post) { | |
setup_postdata($post); | |
?> | |
<a class="post-next" href="<?php the_permalink(); ?>"> | |
<div class="post-nav-wrap" style="background: linear-gradient(0deg,rgba(52,62,71,0.6),rgba(52,62,71,0.3)),url('<?php the_post_thumbnail_url(); ?>');"> | |
<h3 class="post-nav-title"><?php the_title(); ?></h3> | |
<div class="post-nav">Next</div> | |
</div></a> | |
<?php | |
wp_reset_postdata(); | |
} //end foreach | |
} // end if | |
?> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment