wp_query page navigation for custom post type (Joints WP Theme)
-
I am struggling to understand why the built in page navigation of jointswp.com is not working with my custom page template. First off, great theme! I am sure it is something on my end that is causing the issue. I am trying to pull a maximum of 6 posts from my custom post type of “portfolio”, the rest of the posts I want to be displayed with pagination. My exact code works perfectly on an archive page, but on a page template the navigation doesn’t display. Any help would be appreciated. Thanks
<?php /* Template Name: Portfolio Page */ ?> <?php get_header(); ?> <div class="row section-row-container"> <div class="large-12 medium-12 small-12 columns section-title-container"> <h2 class="page-title"><?php the_title(); ?></h2> </div> </div> <div id="gridcontainer"> <?php $type = 'portfolio'; $args = array( 'post_type' => $type, 'post_status' => 'publish', 'posts_per_page' => 6); $my_query = null; $my_query = new WP_Query($args); $counter = 1; //start counter $grids = 2; //Grids per row if( $my_query->have_posts() ) { ?> <div class="row section-row-container"> <?php while ($my_query->have_posts()) : $my_query->the_post(); if($counter == 1) : ?> <div class="griditemleft"> <div class="postimage"> <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail('category-thumbnail'); ?></a> </div> <h2><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2> <p class="post-date-portfolio">Posted On <time datetime="<?php echo the_time('Y-m-j'); ?>" pubdate><?php the_time('F jS, Y'); ?></time> <?php $categories = get_the_category(); if ( ! empty( $categories ) ) { echo '| <a href="' . esc_url( get_category_link( $categories[0]->term_id ) ) . '">' . esc_html( $categories[0]->name ) . '</a>'; } ?></p> </div> <?php elseif($counter == $grids) : ?> <div class="griditemright"> <div class="postimage"> <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail('category-thumbnail'); ?></a> </div> <h2><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2> <p class="post-date-portfolio">Posted On <time datetime="<?php echo the_time('Y-m-j'); ?>" pubdate><?php the_time('F jS, Y'); ?></time> <?php $categories = get_the_category(); if ( ! empty( $categories ) ) { echo '| <a href="' . esc_url( get_category_link( $categories[0]->term_id ) ) . '">' . esc_html( $categories[0]->name ) . '</a>'; } ?></p> </div> <div class="cleargrid"></div> <?php $counter = 0; endif; ?> <?php $counter++; endwhile;?> </div> <?php } wp_reset_postdata(); ?> </div> <?php joints_page_navi(); ?> <?php get_footer(); ?>
Here is the code for the joints_page_navi();
<?php // Numeric Page Navi (built into the theme by default) function joints_page_navi($before = '', $after = '') { global $wpdb, $wp_query; $request = $wp_query->request; $posts_per_page = intval(get_query_var('posts_per_page')); $paged = intval(get_query_var('paged')); $numposts = $wp_query->found_posts; $max_page = $wp_query->max_num_pages; if ( $numposts <= $posts_per_page ) { return; } if(empty($paged) || $paged == 0) { $paged = 1; } $pages_to_show = 7; $pages_to_show_minus_1 = $pages_to_show-1; $half_page_start = floor($pages_to_show_minus_1/2); $half_page_end = ceil($pages_to_show_minus_1/2); $start_page = $paged - $half_page_start; if($start_page <= 0) { $start_page = 1; } $end_page = $paged + $half_page_end; if(($end_page - $start_page) != $pages_to_show_minus_1) { $end_page = $start_page + $pages_to_show_minus_1; } if($end_page > $max_page) { $start_page = $max_page - $pages_to_show_minus_1; $end_page = $max_page; } if($start_page <= 0) { $start_page = 1; } echo $before.'<div class="row section-row-container"><nav class="page-navigation"><ul class="pagination">'.""; if ($start_page >= 2 && $pages_to_show < $max_page) { $first_page_text = __( "First", 'jointstheme' ); echo '<li><a href="'.get_pagenum_link().'" title="'.$first_page_text.'">'.$first_page_text.'</a></li>'; } echo '<li>'; previous_posts_link('<<'); echo '</li>'; for($i = $start_page; $i <= $end_page; $i++) { if($i == $paged) { echo '<li class="current"><a href="'.get_pagenum_link($i).'">'.$i.'</a></li>'; } else { echo '<li><a href="'.get_pagenum_link($i).'">'.$i.'</a></li>'; } } echo '<li>'; next_posts_link('>>'); echo '</li>'; if ($end_page < $max_page) { $last_page_text = __( "Last", 'jointstheme' ); echo '<li><a href="'.get_pagenum_link($max_page).'" title="'.$last_page_text.'">'.$last_page_text.'</a></li>'; } echo '</ul></nav></div>'.$after.""; } /* End page navi */ ?>
Thanks!
Viewing 7 replies - 1 through 7 (of 7 total)
Viewing 7 replies - 1 through 7 (of 7 total)
- The topic ‘wp_query page navigation for custom post type (Joints WP Theme)’ is closed to new replies.