• Hi there,

    I have a custom page template called blog.php – all I want this page to do is display 10 posts per page, but I want it to include Previous and Next Entries links at the bottom of the page.

    I’ve tried a range of things from the Codex but haven’t been able to get it to work. I’m hoping someone can point me in the right direction.

    Here is the code from the page:

    <?php
    /*
    Template Name: Blog
    */
    
    get_header(); ?>
    
    	<div id="columns">
    	<div id="centercol">
    		<div class="box">
    			<div class="top"></div>
    				<div class="spacer">
    					<div id="content" class="narrowcolumn">
    
    			<?php
    
    			// Page ID 21 will get category ID 12 posts, page 16 will get category 32 posts, page 28 will get category 17 posts
    			if (is_page('21') ) {
    			$cat = array(12);
    			} elseif ( is_page('16') ) {
    			$cat = array(32);
    			} elseif ( is_page('28') ) {
    			$cat = array(17);
    			} else {
    			$cat = '';
    			}
    
    			$category = 'Blog'; // Category 1 = Blog
    			$settings=array('category__in' => $cat,'category_name' => $category);
    			$query = new WP_Query($settings); 
    
    		?>
    
    		<?php if( $query->have_posts() ) : ?>
    
    			<?php while ($query->have_posts()) : $query->the_post(); ?>
    
    				<?php
    
    				global $wp_query;
    				$wp_query->in_the_loop = true;
    
    				?>
    
    				<div id="post-<?php the_ID(); ?>" class="post">
    				<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php _e('Permanent Link to',woothemes); ?> <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    
    				<div class="entry">
                                <?php the_content(); ?>
                            </div>
                            </div>
                            <!--/post-->
    
                                <?php endwhile; else : ?>
    
                        <div class="post box">
                            <div class="entry-head"><h2><?php _e('404 - Not Found',woothemes); ?></h2></div>
                            <div class="entry-content"><p><?php _e('The page you are looking for is not here.',woothemes); ?></p></div>
                        </div>
                        </div>
    
                        <?php endif; ?>
                        </div>
                        <div class="fix"></div>
    			</div>
    			<!--/spacer -->
    			<div class="bot"></div>
    				</div>
    				<!--/box -->
    			</div>
    			<!--/centercol -->
    
    	<?php get_sidebar(); ?>
    
    			<br class="fix" />
    		</div>
    		<!--/columns -->
    
    	<?php get_footer(); ?>
Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter fourseven

    (@fourseven)

    Anyone?

    Thread Starter fourseven

    (@fourseven)

    No luck unfortunately. It works on the front static page when placed in footer.php, but not in the blog.php page (even when including the function to active in the blog.php page itself).

    philipbeel

    (@philipbeel)

    Hey. I had the same issue. Basically the pagenavi plugin wants a GET paramater to tell it what page you are currently on. Permalinks screw with this so we have to manually enter it.

    say for your URL looks like this: https://example.com/films/page/3/

    we need to pass in the page number /3/ into the query_posts(); we can get this out with this PHP function like so:

    function curPageURL() {
    			 	$pageURL = 'http';
    			 	if ($_SERVER["HTTPS"] == "on") {
    			 		$pageURL .= "s";
    			 	}
    			 	$pageURL .= "://";
    			 	if ($_SERVER["SERVER_PORT"] != "80") {
    			 		$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
    			 	} else {
    			  		$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
    			 	}
    
    			 	$urlEnd = substr($pageURL, -3);
    			 	$page = str_replace("/", "", $urlEnd);
    			 	return $page;
    			}
    			//add in the catagory and page number
    			query_posts('cat=7,8,12,13,15&paged='.curPageURL());

    The query_posts() function can then have the &paged paramater passed directly into it dynamically using this funciton.

    Hope this solves your problem!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Navigation page links’ is closed to new replies.