62 | Page-Of-Posts Template for Twenty Twelve


Page templates are a good way of customising the layout of WordPress sites – and the Codex contains the example code of a ‘Page Of Posts’ page template for the current default theme Twenty Eleven. With the future default theme – Twenty Twelve – of the soon to be released next version of WordPresss already published, there is a need for a new example.

As usual, start by creating a child theme of Twenty Twelve.

The ‘Page Of Posts’ page template is straight forward code:

Please use the code from the pastebin http://pastebin.com/yeGnRkbR

There was some problem with the code below which was unfortunately somehow broken – but seems to be fixed now.

 * Template Name: Page of Posts
 * for a child theme of Twenty_Twelve

get_header(); ?>

	<div id="primary" class="site-content">
		<div id="content" role="main">

			$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
			$args= array(
				'category_name' => 'antiquarianism', // Change this category SLUG to suit your use; or see for query parameters http://codex.wordpress.org/Class_Reference/WP_Query#Parameters
				'paged' => $paged
			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>
				<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(); ?>


This entry was posted in Easy Coding for Wordpress, Tips & Tricks, Twenty Twelve, WordPress and tagged , , . Bookmark the permalink.

9 Responses to Page-Of-Posts Template for Twenty Twelve

  1. turiya comments:


    I used this template successfully, thank you!

    Is there a way to make it display full posts instead of excerpts?

    Thank you for your help and for your contributions to the WP forums. Your answers have helped me many times in the last few years.

    • michael replies:

      whether the excerpt or full content gets shown, depends on teh code of content.php – which is called via this line in the template: <?php get_template_part( 'content', get_post_format() ); ?>
      you will need to edit the code of content.php (and the other content-(postformat}.php files is necessary)

  2. james waterhouse comments:

    Hi Alchymyth,

    Thanks for this, I have finally managed to display posts on my homepage without a plugin but I have a few Questions for you.

    I changed the ‘category_name’ => ‘antiquarianism’ to ‘orderby’ => ‘date’ and this organises my posts by most recent. Great!

    The titles do not display at the top of each article. How do i do this? (I would like them to be permalinked to the article post itself)

    I would like to display the first 50 words of the article and not the whole article content. How can i achieve this?

    I would also like to display the author, time of post, number of comments and the categories the article is attached to. Any ideas? (I would like these to be displayed directly under the title)

    I know I have asked a lot of questions but any guidance you could provide me would be greatly appreciated.

    I will also post this in the WordPress Support forums.

    Thanks mate,


  3. Dave comments:

    I’m using Twenty Twelve and this helped, thanks! Wondering if it’s possible to add a custom widget to this template only in the right column? Looking for a way to customize right column widgets on different templates. Thanks,

  4. Steve Shead comments:

    This is great for individual categories – thanks so much for this. My question is, is there a way to substitute

    'category_name' => 'antiquarianism',

    with a query – and then call that query in the pages custom fields? Something like:

    $wp_query = new WP_Query($args);

    …with some manipulation? I’m not good at coding so I have no clue how to extrapolate that.


  5. Amanda comments:

    Hey! This post helped me out a lot, thank you soooo much!!

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>


This site uses Akismet to reduce spam. Learn how your comment data is processed.