• 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)
  • I’m running into the same issue. Have you found a solution yet?

    Just to make sure I’m understanding this correctly, the pagination isn’t displaying when you attempt to display posts on a page template – correct?

    Hey up,

    So the problem is that we are using custom queries that aren’t called $wp_query which is what this function searches for. This site has a quick fix by storing $wp_query as a temp variable and then just reassigning it once you’re done…

    More info here: http://darrinb.com/notes/2009/how-to-paginate-a-custom-wordpress-query-loop/3/

    …but I’d rather figure out how to do it properly…any ideas?

    (JointsWP is awesome btw, keep up the good work!)

    Just another quick heads up which I was batting my head against for a short while:

    http://www.position-relative.com/2010/the-good-and-bad/botheration/wordpress-custom-post-types-and-paging-problems/

    You cannot create a Page using the same string name as your registered custom post type.

    Also, I’ve found a fix I think, but I’ll do a pull request and you can take a look for yourselves and see if it works.

    https://github.com/JeremyEnglert/JointsWP/compare/4.0…porridj:4.0

    Did anyone ever find out a way to fix this? I’m having the same issue with my blog page. I created a custom template for it template-blog.php and the pagenavi is not working

    http://www.vtsociety.org.php56-16.dfw3-1.websitetestlink.com/newsroom/

    But yet it works fine on my custom post type archive page that i created events-archive.php

    http://www.vtsociety.org.php56-16.dfw3-1.websitetestlink.com/events/

    @acscreative you mind sticking your code somewhere for us to see?

    Happy to try and help if you can show me your template file.

    @porridj, No problem at all.

    <?php get_header(); ?>
    	<div id="content">
    		<header class="article-header blog-int">
    		    <div class="row">
    		    	<?php query_posts('cat=9');
    					if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    				    	<div class="small-12 medium-6 columns blog-img">
    							<?php if (has_post_thumbnail()) echo get_the_post_thumbnail($page->ID, 'event-main'); ?>
    				    	</div>
    				    	<div class="small-12 medium-6 columns blog-title text-left">
    				    		<h4>Breaking News</h4>
    							<h2><?php the_title(); ?></h2>
    							<p><?php the_excerpt(); ?></p>
    				    	</div>
    					<?php endwhile; endif; ?>
    		    	<?php wp_reset_query(); ?>
    		    </div>
    		</header> <!-- end article header -->
    		<div id="inner-content" class="row">
    		    <main id="main" class="large-8 medium-8 columns" role="main">
    		    <h2 class="event-subtitles"><span>Recent</span> Articles</h2>
    		    <?php query_posts('cat=-9');
    				if (have_posts()) : while (have_posts()) : the_post(); ?>
    					<div class="row blog-content" itemprop="articleBody">
    						<div class="small-12 columns">
    							<div class="blog-info">
    								<a href="<?php the_permalink(); ?>"><h4><span><?php the_field('new_post_title'); ?></span> <?php the_title(); ?></h4></a>
    								<p class="blog-meta"><?php the_time('j F, Y') ?> | <?php the_category(', ') ?></p>
    								<p><?php the_excerpt(); ?></p>
    							</div>
    						</div>
    					</div>
    				<?php endwhile; ?>
    					<?php joints_page_navi(); ?>
    				<?php else : ?>
    					<?php get_template_part( 'parts/content', 'missing' ); ?>
    				<?php endif; ?>
    			<?php wp_reset_query(); ?>
    		    </main> <!-- end #main -->
    		    <div id="sidebar1" class="sidebar large-4 medium-4 columns" role="complementary">
    				<?php if ( is_active_sidebar( 'news-sidebar' ) ) : ?>
    					<?php dynamic_sidebar( 'news-sidebar' ); ?>
    					<?php dynamic_sidebar( 'global-sidebar' ); ?>
    				<?php else : ?>
    				<!-- This content shows up if there are no widgets defined in the backend. -->
    				<div class="alert help">
    					<p><?php _e( 'Please activate some Widgets.', 'jointswp' );  ?></p>
    				</div>
    				<?php endif; ?>
    			</div>
    		</div> <!-- end #inner-content -->
    	</div> <!-- end #content -->
    <?php get_footer(); ?>
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.