Skip to content

Instantly share code, notes, and snippets.

@jbynum
Created October 22, 2010 21:38
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbynum/641425 to your computer and use it in GitHub Desktop.
Save jbynum/641425 to your computer and use it in GitHub Desktop.
how to paginate custom post type in wordpress
<?php
$docs = get_posts('numberposts=-1&post_type=page&post_parent=36&orderby=title&order=ASC');
$faculty = array();
foreach ($docs as $doc) {
array_push($faculty, $doc->ID);
}
$currentElement = array_search($post->ID, $faculty);
$next = isset( $faculty[$currentElement+1] ) ? $faculty[$currentElement+1] : null;
$prev = isset($faculty[$currentElement-1]) ? $faculty[$currentElement-1] : null;
if ( !is_null($prev) ) {
$prevDoc = query_posts( array('page_id' => $prev) );
$prevDocHref = '<a href="/faculty/' . $prevDoc[0]->post_name .'" class="docArrows"><img src="'. get_bloginfo('template_directory') .'/images/prevDocArrow.jpg" alt="Previous" /></a>';
}
if ( !is_null($next) ) {
$nextDoc = query_posts( array('page_id' => $next) );
$nextDocHref = '<a href="/faculty/' . $nextDoc[0]->post_name .'" class="docArrows"><img src="'. get_bloginfo('template_directory') .'/images/nextDocArrow.jpg" alt="Next" /></a>';
}
?>
<?= $prevDocHref ?>
<a href="http://cancergrace.net/faculty/">
<img src="<?php bloginfo('template_directory'); ?>/images/meet.jpg" alt="" />
</a>
<?= $nextDocHref ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment