Seguimos con más plantillas para nuestro tema. Las dos siguientes son bastante sencillas.

 

PAGE.PHP

Creamos el archivo page.php y añadimos el siguiente código:

  1. <?php
  2. /**
  3.  * The template for displaying all pages.
  4.  *
  5.  * This is the template that displays all pages by default.
  6.  * Please note that this is the WordPress construct of pages
  7.  * and that other 'pages' on your WordPress site will use a
  8.  * different template.
  9.  *
  10.  * @package WordPress
  11.  * @subpackage New_Theme
  12.  */
  13.  
  14. get_header(); ?>
  15.  
  16. <div id="primary">
  17. <div id="content" role="main">
  18.  
  19. <?php while ( have_posts() ) : the_post(); ?>
  20.  
  21. <?php get_template_part( 'content', 'page' ); ?>
  22.  
  23. <?php comments_template( '', true ); ?>
  24.  
  25. <?php endwhile; // end of the loop. ?>
  26.  
  27. </div><!-- #content -->
  28. </div><!-- #primary -->
  29.  
  30. <?php get_footer(); ?>

Poco puedo comentar del código que no hayamos visto ya. Se llama a la cabecera; se crean las capas para contener el contenido de la página; se crea el bucle que comprobará si hay posts; se recupera la plantilla content-page.php que dará formato al contenido; se recupera la plantilla de comentarios siempre que el administrador los haya habilitado para este contenido, y se recupera la plantilla del pie de página.

 

SIDEBAR-PAGE.PHP

Creamos el archivo sidebar-page.php y añadimos el siguiente código:

  1. <?php
  2. /**
  3.  * Template Name: Sidebar Template
  4.  * Description: A Page Template that adds a sidebar to pages
  5.  *
  6.  * @package WordPress
  7.  * @subpackage New_Theme
  8.  */
  9.  
  10. get_header(); ?>
  11.  
  12. <div id="primary">
  13. <div id="content" role="main">
  14.  
  15. <?php while ( have_posts() ) : the_post(); ?>
  16.  
  17. <?php get_template_part( 'content', 'page' ); ?>
  18.  
  19. <?php comments_template( '', true ); ?>
  20.  
  21. <?php endwhile; // end of the loop. ?>
  22.  
  23. </div><!-- #content -->
  24. </div><!-- #primary -->
  25.  
  26. <?php get_sidebar(); ?>
  27. <?php get_footer(); ?>

Prácticamente es el mismo código, con la única diferencia de que antes de llamar a la plantilla del pie de página llamamos a la plantilla del sidebar.

 

CONTENT-PAGE.PHP

Creamos el archivo content-page.php y añadimos el siguiente código:

  1. <?php
  2. /**
  3.  * The template used for displaying page content in page.php
  4.  *
  5.  * @package WordPress
  6.  * @subpackage New_Theme
  7.  */
  8. ?>
  9.  
  10. <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
  11. <header class="entry-header">
  12. <h1 class="entry-title"><?php the_title(); ?></h1>
  13. </header><!-- .entry-header -->
  14.  
  15. <div class="entry-content">
  16. <?php the_content(); ?>
  17. <?php wp_link_pages( array( 'before' => '<div class="page-link"><span>' . __( 'Pages:', 'newtheme' ) . '</span>', 'after' => '</div>' ) ); ?>
  18. </div><!-- .entry-content -->
  19. <footer class="entry-meta">
  20. <?php edit_post_link( __( 'Edit', 'newtheme' ), '<span class="edit-link">', '</span>' ); ?>
  21. </footer><!-- .entry-meta -->
  22. </article><!-- #post-<?php the_ID(); ?> -->

Este código también es bastante sencillo.

Creamos una etiqueta article, la cual tendrá como id el texto post- seguido del id del post, recuperado con la función the_ID(). Además a esta etiqueta le añadimos las clases de estilos correspondiente a los post, utilizando para ello la función post_class().

A continuación se crea la cabecera del post y se añade el título con la función the_title().

Ya en el contenido se hace una llamada a la función the_content() que recuperará el contenido del post, y seguidamente se hace una llamada a wp_link_pages() que creará un paginador para el post en caso de que sea necesario.

Por último se crea el pie del post con el link para poder editarlo.