Llegamos a las penúltimas plantillas por comentar.

 

TAG.PHP

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

  1. <?php
  2. /**
  3.  * The template used to display Tag Archive pages
  4.  *
  5.  * @package WordPress
  6.  * @subpackage New_Theme
  7.  */
  8.  
  9. get_header(); ?>
  10.  
  11. <section id="primary">
  12. <div id="content" role="main">
  13.  
  14. <?php if ( have_posts() ) : ?>
  15.  
  16. <header class="page-header">
  17. <h1 class="page-title"><?php
  18. printf( __( 'Tag Archives: %s', 'newtheme' ), '<span>' . single_tag_title( '', false ) . '</span>' );
  19. ?></h1>
  20.  
  21. <?php
  22. $tag_description = tag_description();
  23. if ( ! empty( $tag_description ) )
  24. echo apply_filters( 'tag_archive_meta', '<div class="tag-archive-meta">' . $tag_description . '</div>' );
  25. ?>
  26. </header>
  27.  
  28. <?php newtheme_content_nav( 'nav-above' ); ?>
  29.  
  30. <?php /* Start the Loop */ ?>
  31. <?php while ( have_posts() ) : the_post(); ?>
  32.  
  33. <?php
  34. /* Include the Post-Format-specific template for the content.
  35. * If you want to overload this in a child theme then include a file
  36. * called content-___.php (where ___ is the Post Format name) and that will be used instead.
  37. */
  38. get_template_part( 'content', get_post_format() );
  39. ?>
  40.  
  41. <?php endwhile; ?>
  42.  
  43. <?php newtheme_content_nav( 'nav-below' ); ?>
  44.  
  45. <?php else : ?>
  46.  
  47. <article id="post-0" class="post no-results not-found">
  48. <header class="entry-header">
  49. <h1 class="entry-title"><?php _e( 'Nothing Found', 'newtheme' ); ?></h1>
  50. </header><!-- .entry-header -->
  51.  
  52. <div class="entry-content">
  53. <p><?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 'newtheme' ); ?></p>
  54. <?php get_search_form(); ?>
  55. </div><!-- .entry-content -->
  56. </article><!-- #post-0 -->
  57.  
  58. <?php endif; ?>
  59.  
  60. </div><!-- #content -->
  61. </section><!-- #primary -->
  62.  
  63. <?php get_sidebar(); ?>
  64. <?php get_footer(); ?>

Prácticamente es idéntico al resto de plantillas del estilo que hemos visto. En este caso muestra un listado de post por la etiqueta elegida.

 

SEARCH.PHP

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

  1. <?php
  2. /**
  3.  * The template for displaying Search Results pages.
  4.  *
  5.  * @package WordPress
  6.  * @subpackage New_Theme
  7.  */
  8.  
  9. get_header(); ?>
  10.  
  11. <section id="primary">
  12. <div id="content" role="main">
  13.  
  14. <?php if ( have_posts() ) : ?>
  15.  
  16. <header class="page-header">
  17. <h1 class="page-title"><?php printf( __( 'Search Results for: %s', 'newtheme' ), '<span>' . get_search_query() . '</span>' ); ?></h1>
  18. </header>
  19.  
  20. <?php newtheme_content_nav( 'nav-above' ); ?>
  21.  
  22. <?php /* Start the Loop */ ?>
  23. <?php while ( have_posts() ) : the_post(); ?>
  24.  
  25. <?php
  26. /* Include the Post-Format-specific template for the content.
  27. * If you want to overload this in a child theme then include a file
  28. * called content-___.php (where ___ is the Post Format name) and that will be used instead.
  29. */
  30. get_template_part( 'content', get_post_format() );
  31. ?>
  32.  
  33. <?php endwhile; ?>
  34.  
  35. <?php newtheme_content_nav( 'nav-below' ); ?>
  36.  
  37. <?php else : ?>
  38.  
  39. <article id="post-0" class="post no-results not-found">
  40. <header class="entry-header">
  41. <h1 class="entry-title"><?php _e( 'Nothing Found', 'newtheme' ); ?></h1>
  42. </header><!-- .entry-header -->
  43.  
  44. <div class="entry-content">
  45. <p><?php _e( 'Sorry, but nothing matched your search criteria. Please try again with some different keywords.', 'newtheme' ); ?></p>
  46. <?php get_search_form(); ?>
  47. </div><!-- .entry-content -->
  48. </article><!-- #post-0 -->
  49.  
  50. <?php endif; ?>
  51.  
  52. </div><!-- #content -->
  53. </section><!-- #primary -->
  54.  
  55. <?php get_sidebar(); ?>
  56. <?php get_footer(); ?>

Esta plantilla es la que muestra el listado de post que coinciden con la búsqueda que realiza el usuario.

 

SEARCHFORM.PHP

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

  1. <?php
  2. /**
  3.  * The template for displaying search forms in Twenty Eleven
  4.  *
  5.  * @package WordPress
  6.  * @subpackage New_Theme
  7.  */
  8. ?>
  9. <form method="get" id="searchform" action="<?php echo esc_url( home_url( '/' ) ); ?>">
  10. <label for="s" class="assistive-text"><?php _e( 'Search', 'newtheme' ); ?></label>
  11. <input type="text" class="field" name="s" id="s" placeholder="<?php esc_attr_e( 'Search', 'newtheme' ); ?>" />
  12. <input type="submit" class="submit" name="submit" id="searchsubmit" value="<?php esc_attr_e( 'Search', 'newtheme' ); ?>" />
  13. </form>

Esta plantilla es la que genera el formulario de búsqueda. Como ves no tiene mucho que explicar.

 

IMAGE.PHP

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

  1. <?php
  2. /**
  3.  * The template for displaying image attachments.
  4.  *
  5.  * @package WordPress
  6.  * @subpackage New_Theme
  7.  */
  8.  
  9. get_header(); ?>
  10.  
  11. <div id="primary" class="image-attachment">
  12. <div id="content" role="main">
  13.  
  14. <?php while ( have_posts() ) : the_post(); ?>
  15.  
  16. <nav id="nav-single">
  17. <h3 class="assistive-text"><?php _e( 'Image navigation', 'newtheme' ); ?></h3>
  18. <span class="nav-previous"><?php previous_image_link( false, __( '&larr; Previous' , 'newtheme' ) ); ?></span>
  19. <span class="nav-next"><?php next_image_link( false, __( 'Next &rarr;' , 'newtheme' ) ); ?></span>
  20. </nav><!-- #nav-single -->
  21.  
  22. <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
  23. <header class="entry-header">
  24. <h1 class="entry-title"><?php the_title(); ?></h1>
  25.  
  26. <div class="entry-meta">
  27. <?php
  28. $metadata = wp_get_attachment_metadata();
  29. printf( __( '<span class="meta-prep meta-prep-entry-date">Published </span> <span class="entry-date"><abbr class="published" title="%1$s">%2$s</abbr></span> at <a href="%3$s" title="Link to full-size image">%4$s &times; %5$s</a> in <a href="%6$s" title="Return to %7$s" rel="gallery">%8$s</a>', 'newtheme' ),
  30. esc_attr( get_the_time() ),
  31. get_the_date(),
  32. esc_url( wp_get_attachment_url() ),
  33. $metadata['width'],
  34. $metadata['height'],
  35. esc_url( get_permalink( $post->post_parent ) ),
  36. esc_attr( strip_tags( get_the_title( $post->post_parent ) ) ),
  37. get_the_title( $post->post_parent )
  38. );
  39. ?>
  40. <?php edit_post_link( __( 'Edit', 'newtheme' ), '<span class="edit-link">', '</span>' ); ?>
  41. </div><!-- .entry-meta -->
  42.  
  43. </header><!-- .entry-header -->
  44.  
  45. <div class="entry-content">
  46.  
  47. <div class="entry-attachment">
  48. <div class="attachment">
  49. <?php
  50. /**
  51. * Grab the IDs of all the image attachments in a gallery so we can get the URL of the next adjacent image in a gallery,
  52. * or the first image (if we're looking at the last image in a gallery), or, in a gallery of one, just the link to that image file
  53. */
  54. $attachments = array_values( get_children( array( 'post_parent' => $post->post_parent, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID' ) ) );
  55. foreach ( $attachments as $k => $attachment ) {
  56. if ( $attachment->ID == $post->ID )
  57. break;
  58. }
  59. $k++;
  60. // If there is more than 1 attachment in a gallery
  61. if ( count( $attachments ) > 1 ) {
  62. if ( isset( $attachments[ $k ] ) )
  63. // get the URL of the next image attachment
  64. $next_attachment_url = get_attachment_link( $attachments[ $k ]->ID );
  65. else
  66. // or get the URL of the first image attachment
  67. $next_attachment_url = get_attachment_link( $attachments[ 0 ]->ID );
  68. } else {
  69. // or, if there's only 1 image, get the URL of the image
  70. $next_attachment_url = wp_get_attachment_url();
  71. }
  72. ?>
  73. <a href="<?php echo esc_url( $next_attachment_url ); ?>" title="<?php the_title_attribute(); ?>" rel="attachment"><?php
  74. $attachment_size = apply_filters( 'newtheme_attachment_size', 848 );
  75. echo wp_get_attachment_image( $post->ID, array( $attachment_size, 1024 ) ); // filterable image width with 1024px limit for image height.
  76. ?></a>
  77.  
  78. <?php if ( ! empty( $post->post_excerpt ) ) : ?>
  79. <div class="entry-caption">
  80. <?php the_excerpt(); ?>
  81. </div>
  82. <?php endif; ?>
  83. </div><!-- .attachment -->
  84.  
  85. </div><!-- .entry-attachment -->
  86.  
  87. <div class="entry-description">
  88. <?php the_content(); ?>
  89. <?php wp_link_pages( array( 'before' => '<div class="page-link"><span>' . __( 'Pages:', 'newtheme' ) . '</span>', 'after' => '</div>' ) ); ?>
  90. </div><!-- .entry-description -->
  91.  
  92. </div><!-- .entry-content -->
  93.  
  94. </article><!-- #post-<?php the_ID(); ?> -->
  95.  
  96. <?php comments_template(); ?>
  97.  
  98. <?php endwhile; // end of the loop. ?>
  99.  
  100. </div><!-- #content -->
  101. </div><!-- #primary -->
  102.  
  103. <?php get_footer(); ?>

Esta plantilla nos permite crear una galería de imágenes simplemente añadiendo las imágenes desde la administración.