• Hi, I have been looking for an answer to this problem for a while now. I’m working on a child-theme for Twentytwelve. I have created a Custom Page Template that lists all my latest posts so that i will be able to alter the design for this particular page. This template is set as my front page and a different page is set as my blog posts-page that lists my posts in a traditional fashion.

    This is because i eventually want my front page to display my posts in a certain way (grid). While the posts will be displayed normally in my archives, blog posts-page.

    But when set as “Front page”, the page that uses my Custom Page Template, the page nagivation dosent work. It displays a Back-link that leads to /page/2/ but the page displays the same posts and page as before. However, if i enable the template on a regular page, and dont set it as “Front page”, the page navigation works as intended. How can i fix this?

    Here’s my Custom Page Template: https://pastebin.com/J4nKpUyu

Viewing 8 replies - 1 through 8 (of 8 total)
  • Try checking your site’s error logs for error messages. Your host should be able to help you in accessing your site’s error logs.

    Thread Starter deafdisaster

    (@deafdisaster)

    I’m developing my site locally with XAMPP on Mac, and as far as i know im not getting any errors.

    Have you checked your error.log?

    Thread Starter deafdisaster

    (@deafdisaster)

    Its not creating any error.log-file, even though i have

    define('WP_DEBUG', true);
    define('WP_DEBUG_LOG', true);

    both enabled. And everything else in the installation works fine.

    check if the get_query_var('paged') is set properly; alternatively check and use get_query_var('page')

    Thread Starter deafdisaster

    (@deafdisaster)

    Thanks, using ‘page’ instead seems to have solved the page navigation links.

    But the site still loads the same four posts on every page. So when i click “Older posts” the navigation seems to behave correctly and send me to /page/2/ and displays functioning link to /page/3/. But the posts stay the same.

    Heres the current code.

    <?php
    /**
     * Template Name: Grid Page Template
     *
     */
    
    get_header(); ?>
    
    	<div id="primary" class="site-content">
    		<div id="content" role="main">
    
    		<?php
    			$paged = (get_query_var('page')) ? get_query_var('page') : 1;
    			$args= array(
    			 'page' => $paged,
    			 'posts_per_page' => 4,
    );
    			query_posts($args);
    			if( have_posts() ) :?>
    
    			<?php while ( have_posts() ) : the_post(); ?>
    				<?php get_template_part( 'content', get_post_format() ); ?>
    				<?php comments_template( '', true ); ?>
    			<?php endwhile; // end of the loop. ?>
    
    			<?php twentytwelve_content_nav( 'nav-below' ); ?>
    
    			<?php else : ?>
    			<article id="post-0" class="post no-results not-found">
    				<header class="entry-header">
    					<h1 class="entry-title"><?php _e( 'Nothing Found', 'twentytwelve' ); ?></h1>
    				</header>
    				<div class="entry-content">
    					<p><?php _e( 'Apologies, but no results were found. Perhaps searching will help find a related post.', 'twentytwelve' ); ?></p>
    					<?php get_search_form(); ?>
    				</div><!-- .entry-content -->
    			</article><!-- #post-0 -->
    
    			<?php endif; wp_reset_query(); ?>
    
    		</div><!-- #content -->
    	</div><!-- #primary -->
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    just tested in my local test site in a child of Twenty Twelve;

    should work with (your initial code):

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    			$args= array(
    			 'paged' => $paged,
    			 'posts_per_page' => 4,
    );
    			query_posts($args);

    btw: the query parameter has to stay 'paged' .

    if not, check if any plugin might be interfering;

    temporarily deativate all plugins;
    if it helps, re-activate one plugin at a time to locate the interfering plugin.

    Thread Starter deafdisaster

    (@deafdisaster)

    Hey, thanks for your help. A sort of combination seems to have worked. Im running this now and everything works fine. I really dont understand why, though.

    $paged = (get_query_var('page')) ? get_query_var('page') : 1;
    			$args= array(
    			 'paged' => $paged,
    			 'posts_per_page' => 4,
    );
    			query_posts($args);

    I dosent seem correct as the get_query_var(‘page’) differ from the ‘paged’ => $paged,

    But it works.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Custom Page Template as front page’ is closed to new replies.