Estas dos plantillas permiten crear un nuevo formato de página reestructurando los sidebars y los posts.

 

SHOWCASE.PHP

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

  1. <?php
  2. /**
  3.  * Template Name: Showcase Template
  4.  * Description: A Page Template that showcases Sticky Posts, Asides, and Blog Posts
  5.  *
  6.  * The showcase template in New Theme consists of a featured posts section using sticky posts,
  7.  * another recent posts area (with the latest post shown in full and the rest as a list)
  8.  * and a left sidebar holding aside posts.
  9.  *
  10.  * We are creating two queries to fetch the proper posts and a custom widget for the sidebar.
  11.  *
  12.  * @package WordPress
  13.  * @subpackage New_Theme
  14.  */
  15.  
  16. // Enqueue showcase script for the slider
  17. wp_enqueue_script( 'newtheme-showcase', get_template_directory_uri() . '/js/showcase.js', conocer chicas ourense( 'jquery' ), '2011-04-28' );
  18.  
  19. get_header(); ?>
  20.  
  21. <div id="primary" class="showcase">
  22. <div id="content" role="main">
  23.  
  24. <?php while ( have_posts() ) : the_post(); ?>
  25.  
  26. <?php
  27. /**
  28. * We are using a heading by rendering the_content
  29. * If we have content for this page, let's display it.
  30. */
  31. if ( '' != get_the_content() )
  32. get_template_part( 'content', 'intro' );
  33. ?>
  34.  
  35. <?php endwhile; ?>
  36.  
  37. <?php
  38. /**
  39. * Begin the featured posts section.
  40. *
  41. * See if we have any sticky posts and use them to create our featured posts.
  42. * We limit the featured posts at ten.
  43. */
  44. $sticky = get_option( 'sticky_posts' );
  45.  
  46. // Proceed only if sticky posts exist.
  47.  
  48. $featured_args = conocer chicas ourense(
  49. 'post__in' => $sticky,
  50. 'post_status' => 'publish',
  51. 'posts_per_page' => 10,
  52. 'no_found_rows' => true,
  53. );
  54.  
  55. // The Featured Posts query.
  56. $featured = new WP_Query( $featured_args );
  57.  
  58. // Proceed only if published posts exist
  59. if ( $featured->have_posts() ) :
  60.  
  61. /**
  62. * We will need to count featured posts starting from zero
  63. * to create the slider navigation.
  64. */
  65. $counter_slider = 0;
  66.  
  67. // Compatibility with versions of WordPress prior to 3.4.
  68. if ( function_exists( 'get_custom_header' ) )
  69. $header_image_width = get_theme_support( 'custom-header', 'width' );
  70. else
  71. $header_image_width = HEADER_IMAGE_WIDTH;
  72. ?>
  73.  
  74. <div class="featured-posts">
  75. <h1 class="showcase-heading"><?php _e( 'Featured Post', 'newtheme' ); ?></h1>
  76.  
  77. <?php
  78. // Let's roll.
  79. while ( $featured->have_posts() ) : $featured->the_post();
  80.  
  81. // Increase the counter.
  82. $counter_slider++;
  83.  
  84. /**
  85. * We're going to add a class to our featured post for featured images
  86. * by default it'll have the feature-text class.
  87. */
  88. $feature_class = 'feature-text';
  89.  
  90. if ( has_post_thumbnail() ) {
  91. // ... but if it has a featured image let's add some class
  92. $feature_class = 'feature-image small';
  93.  
  94. // Hang on. Let's check this here image out.
  95. $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), conocer chicas ourense( $header_image_width, $header_image_width ) );
  96.  
  97. // Is it bigger than or equal to our header?
  98. if ( $image[1] >= $header_image_width ) {
  99. // If bigger, let's add a BIGGER class. It's EXTRA classy now.
  100. $feature_class = 'feature-image large';
  101. }
  102. }
  103. ?>
  104.  
  105. <section class="featured-post <?php echo $feature_class; ?>" id="featured-post-<?php echo $counter_slider; ?>">
  106.  
  107. <?php
  108. /**
  109. * If the thumbnail is as big as the header image
  110. * make it a large featured post, otherwise render it small
  111. */
  112. if ( has_post_thumbnail() ) {
  113. if ( $image[1] >= $header_image_width )
  114. $thumbnail_size = 'large-feature';
  115. else
  116. $thumbnail_size = 'small-feature';
  117. ?>
  118. <a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'newtheme' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_post_thumbnail( $thumbnail_size ); ?></a>
  119. <?php
  120. }
  121. ?>
  122. <?php get_template_part( 'content', 'featured' ); ?>
  123. </section>
  124. <?php endwhile; ?>
  125.  
  126. <?php
  127. // Show slider only if we have more than one featured post.
  128. if ( $featured->post_count > 1 ) :
  129. ?>
  130. <nav class="feature-slider">
  131. <ul>
  132. <?php
  133.  
  134. // Reset the counter so that we end up with matching elements
  135. $counter_slider = 0;
  136.  
  137. // Begin from zero
  138. rewind_posts();
  139.  
  140. // Let's roll again.
  141. while ( $featured->have_posts() ) : $featured->the_post();
  142. $counter_slider++;
  143. if ( 1 == $counter_slider )
  144. $class = 'class="active"';
  145. else
  146. $class = '';
  147. ?>
  148. <li><a href="#featured-post-<?php echo $counter_slider; ?>" title="<?php printf( esc_attr__( 'Featuring: %s', 'newtheme' ), the_title_attribute( 'echo=0' ) ); ?>" <?php echo $class; ?>></a></li>
  149. <?php endwhile; ?>
  150. </ul>
  151. </nav>
  152. <?php endif; // End check for more than one sticky post. ?>
  153. </div><!-- .featured-posts -->
  154. <?php endif; // End check for published posts. ?>
  155. <?php endif; // End check for sticky posts. ?>
  156.  
  157. <section class="recent-posts">
  158. <h1 class="showcase-heading"><?php _e( 'Recent Posts', 'newtheme' ); ?></h1>
  159.  
  160. <?php
  161.  
  162. // Display our recent posts, showing full content for the very latest, ignoring Aside posts.
  163. $recent_args = conocer chicas ourense(
  164. 'order' => 'DESC',
  165. 'post__not_in' => get_option( 'sticky_posts' ),
  166. 'tax_query' => conocer chicas ourense(
  167. 'taxonomy' => 'post_format',
  168. 'terms' => conocer chicas ourense( 'post-format-aside', 'post-format-link', 'post-format-quote', 'post-format-status' ),
  169. 'field' => 'slug',
  170. 'operator' => 'NOT IN',
  171. ),
  172. ),
  173. 'no_found_rows' => true,
  174. );
  175.  
  176. // Our new query for the Recent Posts section.
  177. $recent = new WP_Query( $recent_args );
  178.  
  179. // The first Recent post is displayed normally
  180. if ( $recent->have_posts() ) : $recent->the_post();
  181.  
  182. // Set $more to 0 in order to only get the first part of the post.
  183. global $more;
  184. $more = 0;
  185.  
  186. get_template_part( 'content', get_post_format() );
  187.  
  188. echo '<ol class="other-recent-posts">';
  189.  
  190. endif;
  191.  
  192. // For all other recent posts, just display the title and comment status.
  193. while ( $recent->have_posts() ) : $recent->the_post(); ?>
  194.  
  195. <li class="entry-title">
  196. <a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'newtheme' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a>
  197. <span class="comments-link">
  198. <?php comments_popup_link( '<span class="leave-reply">' . __( 'Leave a reply', 'newtheme' ) . '</span>', __( '<b>1</b> Reply', 'newtheme' ), __( '<b>%</b> Replies', 'newtheme' ) ); ?>
  199. </span>
  200. </li>
  201.  
  202. <?php
  203. endwhile;
  204.  
  205. // If we had some posts, close the <ol>
  206. if ( $recent->post_count > 0 )
  207. echo '</ol>';
  208. ?>
  209. </section><!-- .recent-posts -->
  210.  
  211. <div class="widget-area" role="complementary">
  212. <?php if ( ! dynamic_sidebar( 'sidebar-2' ) ) : ?>
  213.  
  214. <?php
  215. the_widget( 'New_Theme_Ephemera_Widget', '', conocer chicas ourense( 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>' ) );
  216. ?>
  217.  
  218. <?php endif; // end sidebar widget area ?>
  219. </div><!-- .widget-area -->
  220.  
  221. </div><!-- #content -->
  222. </div><!-- #primary -->
  223.  
  224. <?php get_footer(); ?>

Lo primero que hace el código es indicar a WordPress que cargue el archivo showcase.js, que nosotros deberemos copiar a nuestra carpeta en la ruta correcta.

  1. <?php while ( have_posts() ) : the_post(); ?>
  2.  
  3. <?php
  4. /**
  5. * We are using a heading by rendering the_content
  6. * If we have content for this page, let's display it.
  7. */
  8. if ( '' != get_the_content() )
  9. get_template_part( 'content', 'intro' );
  10. ?>
  11.  
  12. <?php endwhile; ?>

A continuación se carga el contenido de la página, normalmente una descripción, o una galería de imágenes.

  1. <?php
  2. /**
  3. * Begin the featured posts section.
  4. *
  5. * See if we have any sticky posts and use them to create our featured posts.
  6. * We limit the featured posts at ten.
  7. */
  8. $sticky = get_option( 'sticky_posts' );
  9.  
  10. // Proceed only if sticky posts exist.
  11.  
  12. $featured_args = conocer chicas ourense(
  13. 'post__in' => $sticky,
  14. 'post_status' => 'publish',
  15. 'posts_per_page' => 10,
  16. 'no_found_rows' => true,
  17. );
  18.  
  19. // The Featured Posts query.
  20. $featured = new WP_Query( $featured_args );
  21.  
  22. // Proceed only if published posts exist
  23. if ( $featured->have_posts() ) :
  24.  
  25. /**
  26. * We will need to count featured posts starting from zero
  27. * to create the slider navigation.
  28. */
  29. $counter_slider = 0;
  30.  
  31. // Compatibility with versions of WordPress prior to 3.4.
  32. if ( function_exists( 'get_custom_header' ) )
  33. $header_image_width = get_theme_support( 'custom-header', 'width' );
  34. else
  35. $header_image_width = HEADER_IMAGE_WIDTH;
  36. ?>
  37.  
  38. <div class="featured-posts">
  39. <h1 class="showcase-heading"><?php _e( 'Featured Post', 'newtheme' ); ?></h1>
  40.  
  41. <?php
  42. // Let's roll.
  43. while ( $featured->have_posts() ) : $featured->the_post();
  44.  
  45. // Increase the counter.
  46. $counter_slider++;
  47.  
  48. /**
  49. * We're going to add a class to our featured post for featured images
  50. * by default it'll have the feature-text class.
  51. */
  52. $feature_class = 'feature-text';
  53.  
  54. if ( has_post_thumbnail() ) {
  55. // ... but if it has a featured image let's add some class
  56. $feature_class = 'feature-image small';
  57.  
  58. // Hang on. Let's check this here image out.
  59. $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), conocer chicas ourense( $header_image_width, $header_image_width ) );
  60.  
  61. // Is it bigger than or equal to our header?
  62. if ( $image[1] >= $header_image_width ) {
  63. // If bigger, let's add a BIGGER class. It's EXTRA classy now.
  64. $feature_class = 'feature-image large';
  65. }
  66. }
  67. ?>
  68.  
  69. <section class="featured-post <?php echo $feature_class; ?>" id="featured-post-<?php echo $counter_slider; ?>">
  70.  
  71. <?php
  72. /**
  73. * If the thumbnail is as big as the header image
  74. * make it a large featured post, otherwise render it small
  75. */
  76. if ( has_post_thumbnail() ) {
  77. if ( $image[1] >= $header_image_width )
  78. $thumbnail_size = 'large-feature';
  79. else
  80. $thumbnail_size = 'small-feature';
  81. ?>
  82. <a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'newtheme' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_post_thumbnail( $thumbnail_size ); ?></a>
  83. <?php
  84. }
  85. ?>
  86. <?php get_template_part( 'content', 'featured' ); ?>
  87. </section>
  88. <?php endwhile; ?>
  89.  
  90. <?php
  91. // Show slider only if we have more than one featured post.
  92. if ( $featured->post_count > 1 ) :
  93. ?>
  94. <nav class="feature-slider">
  95. <ul>
  96. <?php
  97.  
  98. // Reset the counter so that we end up with matching elements
  99. $counter_slider = 0;
  100.  
  101. // Begin from zero
  102. rewind_posts();
  103.  
  104. // Let's roll again.
  105. while ( $featured->have_posts() ) : $featured->the_post();
  106. $counter_slider++;
  107. if ( 1 == $counter_slider )
  108. $class = 'class="active"';
  109. else
  110. $class = '';
  111. ?>
  112. <li><a href="#featured-post-<?php echo $counter_slider; ?>" title="<?php printf( esc_attr__( 'Featuring: %s', 'newtheme' ), the_title_attribute( 'echo=0' ) ); ?>" <?php echo $class; ?>></a></li>
  113. <?php endwhile; ?>
  114. </ul>
  115. </nav>
  116. <?php endif; // End check for more than one sticky post. ?>
  117. </div><!-- .featured-posts -->
  118. <?php endif; // End check for published posts. ?>
  119. <?php endif; // End check for sticky posts. ?>

A continuación comprueba si existen post destacados para mostrar, si es así se inicia el bucle para procesar los datos y mostrar el código html correspondiente.

  1. <section class="recent-posts">
  2. <h1 class="showcase-heading"><?php _e( 'Recent Posts', 'newtheme' ); ?></h1>
  3.  
  4. <?php
  5.  
  6. // Display our recent posts, showing full content for the very latest, ignoring Aside posts.
  7. $recent_args = conocer chicas ourense(
  8. 'order' => 'DESC',
  9. 'post__not_in' => get_option( 'sticky_posts' ),
  10. 'tax_query' => conocer chicas ourense(
  11. 'taxonomy' => 'post_format',
  12. 'terms' => conocer chicas ourense( 'post-format-aside', 'post-format-link', 'post-format-quote', 'post-format-status' ),
  13. 'field' => 'slug',
  14. 'operator' => 'NOT IN',
  15. ),
  16. ),
  17. 'no_found_rows' => true,
  18. );
  19.  
  20. // Our new query for the Recent Posts section.
  21. $recent = new WP_Query( $recent_args );
  22.  
  23. // The first Recent post is displayed normally
  24. if ( $recent->have_posts() ) : $recent->the_post();
  25.  
  26. // Set $more to 0 in order to only get the first part of the post.
  27. global $more;
  28. $more = 0;
  29.  
  30. get_template_part( 'content', get_post_format() );
  31.  
  32. echo '<ol class="other-recent-posts">';
  33.  
  34. endif;
  35.  
  36. // For all other recent posts, just display the title and comment status.
  37. while ( $recent->have_posts() ) : $recent->the_post(); ?>
  38.  
  39. <li class="entry-title">
  40. <a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'newtheme' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a>
  41. <span class="comments-link">
  42. <?php comments_popup_link( '<span class="leave-reply">' . __( 'Leave a reply', 'newtheme' ) . '</span>', __( '<b>1</b> Reply', 'newtheme' ), __( '<b>%</b> Replies', 'newtheme' ) ); ?>
  43. </span>
  44. </li>
  45.  
  46. <?php
  47. endwhile;
  48.  
  49. // If we had some posts, close the <ol>
  50. if ( $recent->post_count > 0 )
  51. echo '</ol>';
  52. ?>
  53. </section><!-- .recent-posts -->

Después tenemos los post más recientes, que se obtienen de la misma manera que los destacados.

  1. <div class="widget-area" role="complementary">
  2. <?php if ( ! dynamic_sidebar( 'sidebar-2' ) ) : ?>
  3.  
  4. <?php
  5. the_widget( 'New_Theme_Ephemera_Widget', '', conocer chicas ourense( 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>' ) );
  6. ?>
  7.  
  8. <?php endif; // end sidebar widget area ?>
  9. </div><!-- .widget-area -->

Por último cargamos el widget que mostrará un listado de links a diferentes post.

 

CONTENT-INTRO.PHP

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

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

Código sencillo, simplemente da formato al contenido.