Skip to content

Instantly share code, notes, and snippets.

@rachelmccollin
Last active July 21, 2020 23:15
Show Gist options
  • Save rachelmccollin/0decce4b62dc7ed9d8cc515d4de2be63 to your computer and use it in GitHub Desktop.
Save rachelmccollin/0decce4b62dc7ed9d8cc515d4de2be63 to your computer and use it in GitHub Desktop.
Ultimate guide to WordPress page templates
<?php
/*
The include for displaying the loop in static pages.
*/
if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php if ( is_front_page() ) { ?>
<?php } else { ?>
<h2 class="entry-title"><?php the_title(); ?></h2>
<?php } ?>
<section class="entry-content">
<?php the_content(); ?>
</section><!-- .entry-content -->
</article><!-- #post-## -->
<?php do_action( 'compass_comments' ); /* action hook for comments - pluggable so you can override it if you don't want comments displayed */?>
<?php endwhile; ?>
<?php
/**
* The template for displaying all pages.
*/
get_header(); ?>
<?php
/* Run the page loop to output the page content.
*/
get_template_part( 'loop', 'page' );
?>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
.content {
width: 65%;
float: left;
}
.sidebar {
width: 32%;
float: right;
}
.page-template-template-page-full-width .content,
.page-template-template-page-full-width .sidebar {
width: 100%;
float: none;
clear: both;
}
<?php
/**
* Template Name: Full width page
*
* A custom page template without sidebar.
*
*/
get_header(); ?>
<?php
/* Run the page loop to output the page content.
*/
get_template_part( 'loop', 'page' );
?>
<?php get_footer(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment