From Page Templates

Top ↑

Additional Examples

The following are instructional examples of custom page template files. Please Note: Your WordPress theme’s template file structure and HTMLHTML HTML is an acronym for Hyper Text Markup Language. It is a markup language that is used in the development of web pages and websites. structure may be different.

Top ↑

Archives with Content

This example of a page template displays the content at the top, then a list of archives (by month), then the site categories below that.

Save this to archives-content.php and then assign the Archives with Content template to your new page:

Template Name: Archives with Content

get_header(); ?>
<div id="content" class="widecolumn">
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <div class="post">
        <h2 id="post-<?php the_ID(); ?>"><?php the_title(); ?></h2>
        <div class="entry-content">
            <?php the_content( 'Read the rest of this page »' ); ?>
    <?php endwhile; endif; ?>
<?php edit_post_link( 'Edit this entry.', '<p>', '</p>' ); ?>
<div id="main">
    <?php get_search_form(); ?>
    <h2>Archives by Month:</h2>
        <?php wp_get_archives( 'type=monthly' ); ?>
    <h2>Archives by Subject:</h2>
        <?php wp_list_categories(); ?>
<?php get_footer(); ?>

Top ↑

A Page of Posts

The following custom page template displays the content of the page, followed by the posts from two specific categories (specified by their categoryCategory The 'category' taxonomy lets you group posts / content together that share a common bond. Categories are pre-defined and broad ranging. slugs). It is designed to work within a child themeChild theme A Child Theme is a customized theme based upon a Parent Theme. It’s considered best practice to create a child theme if you want to modify the CSS of your theme. of the Twenty Thirteen theme. If you are using a different theme, you need to replicate the HTML structure of your own theme within this template.

Save this to posts-page.php and then assign the Page of Posts template to your new page:

Template Name: Page of Posts

/* This example is for a child theme of Twenty Thirteen:
 * You'll need to adapt it to the HTML structure of your own theme.

get_header(); ?>

	<div id="primary" class="content-area">
		<div id="content" class="site-content" role="main">
        /* The loop: the_post retrieves the content
         * of the new Page you created to list the posts,
         * e.g., an intro describing the posts shown listed on this Page..
        if ( have_posts() ) : while ( have_posts() ) : the_post();

              // Display content of page
              get_template_part( 'content', get_post_format() );


        $paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;

        $args = array(
            // Change these category SLUGS to suit your use.
            'category_name' => 'music, videos',
            'paged' => $paged

        $list_of_posts = new WP_Query( $args ); ?>
        <?php if ( $list_of_posts->have_posts() ) : ?>
			<?php /* The loop */ ?>
			<?php while ( $list_of_posts->have_posts() ) : $list_of_posts->the_post(); ?>
				<?php // Display content of posts ?>
				<?php get_template_part( 'content', get_post_format() ); ?>
			<?php endwhile; ?>

			<?php twentythirteen_paging_nav(); ?>

		<?php else : ?>
			<?php get_template_part( 'content', 'none' ); ?>
		<?php endif; ?>

		</div><!-- #content -->
	</div><!-- #primary -->

<?php get_footer(); ?>