Estas en: Home > content

Entradas etiquetadas con content

Cron Job WordPress

WordPress 3.x para desarrolladores: Temas y plantillas, showcase.php y content-intro.php

0

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', https://www.interadictos.es/mujeres-solteras-de-mendoza-buscan-pareja/( '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. if ( ! apps para conocer mujeres mayores( $sticky ) ) :
  48.  
  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 ), https://www.interadictos.es/mujeres-solteras-de-mendoza-buscan-pareja/( $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. 'order' => 'DESC',
  164. 'post__not_in' => get_option( 'sticky_posts' ),
  165. 'taxonomy' => 'post_format',
  166. 'terms' => https://www.interadictos.es/mujeres-solteras-de-mendoza-buscan-pareja/( 'post-format-aside', 'post-format-link', 'post-format-quote', 'post-format-status' ),
  167. 'field' => 'slug',
  168. 'operator' => 'NOT IN',
  169. ),
  170. ),
  171. 'no_found_rows' => true,
  172. );
  173.  
  174. // Our new query for the Recent Posts section.
  175. $recent = new WP_Query( $recent_args );
  176.  
  177. // The first Recent post is displayed normally
  178. if ( $recent->have_posts() ) : $recent->the_post();
  179.  
  180. // Set $more to 0 in order to only get the first part of the post.
  181. global $more;
  182. $more = 0;
  183.  
  184. get_template_part( 'content', get_post_format() );
  185.  
  186. echo '<ol class="other-recent-posts">';
  187.  
  188. endif;
  189.  
  190. // For all other recent posts, just display the title and comment status.
  191. while ( $recent->have_posts() ) : $recent->the_post(); ?>
  192.  
  193. <li class="entry-title">
  194. <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>
  195. <span class="comments-link">
  196. <?php comments_popup_link( '<span class="leave-reply">' . __( 'Leave a reply', 'newtheme' ) . '</span>', __( '<b>1</b> Reply', 'newtheme' ), __( '<b>%</b> Replies', 'newtheme' ) ); ?>
  197. </span>
  198. </li>
  199.  
  200. <?php
  201. endwhile;
  202.  
  203. // If we had some posts, close the <ol>
  204. if ( $recent->post_count > 0 )
  205. echo '</ol>';
  206. ?>
  207. </section><!-- .recent-posts -->
  208.  
  209. <div class="widget-area" role="complementary">
  210. <?php if ( ! dynamic_sidebar( 'sidebar-2' ) ) : ?>
  211.  
  212. <?php
  213. the_widget( 'New_Theme_Ephemera_Widget', '', https://www.interadictos.es/mujeres-solteras-de-mendoza-buscan-pareja/( 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>' ) );
  214. ?>
  215.  
  216. <?php endif; // end sidebar widget area ?>
  217. </div><!-- .widget-area -->
  218.  
  219. </div><!-- #content -->
  220. </div><!-- #primary -->
  221.  
  222. <?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. if ( ! apps para conocer mujeres mayores( $sticky ) ) :
  12.  
  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 ), https://www.interadictos.es/mujeres-solteras-de-mendoza-buscan-pareja/( $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. 'order' => 'DESC',
  8. 'post__not_in' => get_option( 'sticky_posts' ),
  9. 'taxonomy' => 'post_format',
  10. 'terms' => https://www.interadictos.es/mujeres-solteras-de-mendoza-buscan-pareja/( 'post-format-aside', 'post-format-link', 'post-format-quote', 'post-format-status' ),
  11. 'field' => 'slug',
  12. 'operator' => 'NOT IN',
  13. ),
  14. ),
  15. 'no_found_rows' => true,
  16. );
  17.  
  18. // Our new query for the Recent Posts section.
  19. $recent = new WP_Query( $recent_args );
  20.  
  21. // The first Recent post is displayed normally
  22. if ( $recent->have_posts() ) : $recent->the_post();
  23.  
  24. // Set $more to 0 in order to only get the first part of the post.
  25. global $more;
  26. $more = 0;
  27.  
  28. get_template_part( 'content', get_post_format() );
  29.  
  30. echo '<ol class="other-recent-posts">';
  31.  
  32. endif;
  33.  
  34. // For all other recent posts, just display the title and comment status.
  35. while ( $recent->have_posts() ) : $recent->the_post(); ?>
  36.  
  37. <li class="entry-title">
  38. <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>
  39. <span class="comments-link">
  40. <?php comments_popup_link( '<span class="leave-reply">' . __( 'Leave a reply', 'newtheme' ) . '</span>', __( '<b>1</b> Reply', 'newtheme' ), __( '<b>%</b> Replies', 'newtheme' ) ); ?>
  41. </span>
  42. </li>
  43.  
  44. <?php
  45. endwhile;
  46.  
  47. // If we had some posts, close the <ol>
  48. if ( $recent->post_count > 0 )
  49. echo '</ol>';
  50. ?>
  51. </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', '', https://www.interadictos.es/mujeres-solteras-de-mendoza-buscan-pareja/( '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( https://www.interadictos.es/mujeres-solteras-de-mendoza-buscan-pareja/( '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.

Cron Job WordPress

WordPress 3.x para desarrolladores: Temas y plantillas, content-image.php, content-link.php, content-quote.php y content-status.php

0

CONTENT-IMAGE.PHP

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

  1. <?php
  2. /**
  3.  * The template for displaying posts in the Image Post Format on index and archive pages
  4.  *
  5.  * Learn more: http://codex.wordpress.org/Post_Formats
  6.  *
  7.  * @package WordPress
  8.  * @subpackage New_Theme
  9.  */
  10. ?>
  11. <article id="post-<?php the_ID(); ?>" <?php post_class( 'indexed' ); ?>>
  12. <header class="entry-header">
  13. <hgroup>
  14. <h2 class="entry-title"><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></h2>
  15. <h3 class="entry-format"><?php _e( 'Image', 'newtheme' ); ?></h3>
  16. </hgroup>
  17.  
  18. <?php if ( comments_open() && ! post_password_required() ) : ?>
  19. <div class="comments-link">
  20. <?php comments_popup_link( '<span class="leave-reply">' . __( "Reply", 'newtheme' ) . '</span>', _x( '1', 'comments number', 'newtheme' ), _x( '%', 'comments number', 'newtheme' ) ); ?>
  21. </div>
  22. <?php endif; ?>
  23. </header><!-- .entry-header -->
  24.  
  25. <div class="entry-content">
  26. <?php the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'newtheme' ) ); ?>
  27. <?php wp_link_pages( https://www.interadictos.es/mujeres-solteras-de-mendoza-buscan-pareja/( 'before' => '<div class="page-link"><span>' . __( 'Pages:', 'newtheme' ) . '</span>', 'after' => '</div>' ) ); ?>
  28. </div><!-- .entry-content -->
  29.  
  30. <footer class="entry-meta">
  31. <div class="entry-meta">
  32. <?php
  33. printf( __( '<a href="%1$s" rel="bookmark"><time class="entry-date" datetime="%2$s" pubdate>%3$s</time></a><span class="by-author"> <span class="sep"> by </span> <span class="author vcard"><a class="url fn n" href="%4$s" title="%5$s" rel="author">%6$s</a></span></span>', 'newtheme' ),
  34. esc_url( get_permalink() ),
  35. get_the_date( 'c' ),
  36. get_the_date(),
  37. esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
  38. esc_attr( sprintf( __( 'View all posts by %s', 'newtheme' ), get_the_author() ) ),
  39. get_the_author()
  40. );
  41. ?>
  42. </div><!-- .entry-meta -->
  43. <div class="entry-meta">
  44. <?php
  45. /* translators: used between list items, there is a space after the comma */
  46. $categories_list = get_the_category_list( __( ', ', 'newtheme' ) );
  47. if ( $categories_list ):
  48. ?>
  49. <span class="cat-links">
  50. <?php printf( __( '<span class="%1$s">Posted in</span> %2$s', 'newtheme' ), 'entry-utility-prep entry-utility-prep-cat-links', $categories_list ); ?>
  51. </span>
  52. <?php endif; // End if categories ?>
  53. <?php
  54. /* translators: used between list items, there is a space after the comma */
  55. $tags_list = get_the_tag_list( '', __( ', ', 'newtheme' ) );
  56. if ( $tags_list ): ?>
  57. <span class="tag-links">
  58. <?php printf( __( '<span class="%1$s">Tagged</span> %2$s', 'newtheme' ), 'entry-utility-prep entry-utility-prep-tag-links', $tags_list ); ?>
  59. </span>
  60. <?php endif; // End if $tags_list ?>
  61.  
  62. <?php if ( comments_open() ) : ?>
  63. <span class="comments-link"><?php comments_popup_link( '<span class="leave-reply">' . __( 'Leave a reply', 'newtheme' ) . '</span>', __( '<b>1</b> Reply', 'newtheme' ), __( '<b>%</b> Replies', 'newtheme' ) ); ?></span>
  64. <?php endif; // End if comments_open() ?>
  65. </div><!-- .entry-meta -->
  66.  
  67. <?php edit_post_link( __( 'Edit', 'newtheme' ), '<span class="edit-link">', '</span>' ); ?>
  68. </footer><!-- #entry-meta -->
  69. </article><!-- #post-<?php the_ID(); ?> -->

Este tipo de contenido simplemente muestra una imagen y su respectivo título.

 

CONTENT-LINK.PHP

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

  1. <?php
  2. /**
  3.  * The template for displaying posts in the Link Post Format on index and archive pages
  4.  *
  5.  * Learn more: http://codex.wordpress.org/Post_Formats
  6.  *
  7.  * @package WordPress
  8.  * @subpackage New_Theme
  9.  */
  10. ?>
  11.  
  12. <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
  13. <header class="entry-header">
  14. <hgroup>
  15. <h2 class="entry-title"><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></h2>
  16. <h3 class="entry-format"><?php _e( 'Link', 'newtheme' ); ?></h3>
  17. </hgroup>
  18.  
  19. <?php if ( comments_open() && ! post_password_required() ) : ?>
  20. <div class="comments-link">
  21. <?php comments_popup_link( '<span class="leave-reply">' . __( 'Reply', 'newtheme' ) . '</span>', _x( '1', 'comments number', 'newtheme' ), _x( '%', 'comments number', 'newtheme' ) ); ?>
  22. </div>
  23. <?php endif; ?>
  24. </header><!-- .entry-header -->
  25.  
  26. <?php if ( is_search() ) : // Only display Excerpts for Search ?>
  27. <div class="entry-summary">
  28. <?php the_excerpt(); ?>
  29. </div><!-- .entry-summary -->
  30. <?php else : ?>
  31. <div class="entry-content">
  32. <?php the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'newtheme' ) ); ?>
  33. <?php wp_link_pages( https://www.interadictos.es/mujeres-solteras-de-mendoza-buscan-pareja/( 'before' => '<div class="page-link"><span>' . __( 'Pages:', 'newtheme' ) . '</span>', 'after' => '</div>' ) ); ?>
  34. </div><!-- .entry-content -->
  35. <?php endif; ?>
  36.  
  37. <footer class="entry-meta">
  38. <?php newtheme_posted_on(); ?>
  39. <?php if ( comments_open() ) : ?>
  40. <span class="sep"> | </span>
  41. <span class="comments-link"><?php comments_popup_link( '<span class="leave-reply">' . __( 'Leave a reply', 'newtheme' ) . '</span>', __( '<b>1</b> Reply', 'newtheme' ), __( '<b>%</b> Replies', 'newtheme' ) ); ?></span>
  42. <?php endif; ?>
  43. <?php edit_post_link( __( 'Edit', 'newtheme' ), '<span class="edit-link">', '</span>' ); ?>
  44. </footer><!-- #entry-meta -->
  45. </article><!-- #post-<?php the_ID(); ?> -->

Este contenido es más sencillo aún. Simplemente mostramos un link o un conjunto de estos.

 

CONTENT-QUOTE.PHP

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

  1. <?php
  2.  
  3. <?php
  4. /**
  5.  * The default template for displaying content
  6.  *
  7.  * @package WordPress
  8.  * @subpackage New_Theme
  9.  */
  10. ?>
  11.  
  12. <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
  13. <header class="entry-header">
  14. <hgroup>
  15. <h2 class="entry-title"><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></h2>
  16. <h3 class="entry-format"><?php _e( 'Quote', 'newtheme' ); ?></h3>
  17. </hgroup>
  18.  
  19. <div class="entry-meta">
  20. <?php newtheme_posted_on(); ?>
  21. </div><!-- .entry-meta -->
  22.  
  23. <?php if ( comments_open() && ! post_password_required() ) : ?>
  24. <div class="comments-link">
  25. <?php comments_popup_link( '<span class="leave-reply">' . __( 'Reply', 'newtheme' ) . '</span>', _x( '1', 'comments number', 'newtheme' ), _x( '%', 'comments number', 'newtheme' ) ); ?>
  26. </div>
  27. <?php endif; ?>
  28. </header><!-- .entry-header -->
  29.  
  30. <?php if ( is_search() ) : // Only display Excerpts for Search ?>
  31. <div class="entry-summary">
  32. <?php the_excerpt(); ?>
  33. </div><!-- .entry-summary -->
  34. <?php else : ?>
  35. <div class="entry-content">
  36. <?php the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'newtheme' ) ); ?>
  37. <?php wp_link_pages( https://www.interadictos.es/mujeres-solteras-de-mendoza-buscan-pareja/( 'before' => '<div class="page-link"><span>' . __( 'Pages:', 'newtheme' ) . '</span>', 'after' => '</div>' ) ); ?>
  38. </div><!-- .entry-content -->
  39. <?php endif; ?>
  40.  
  41. <footer class="entry-meta">
  42. <?php $show_sep = false; ?>
  43. <?php
  44. /* translators: used between list items, there is a space after the comma */
  45. $categories_list = get_the_category_list( __( ', ', 'newtheme' ) );
  46. if ( $categories_list ):
  47. ?>
  48. <span class="cat-links">
  49. <?php printf( __( '<span class="%1$s">Posted in</span> %2$s', 'newtheme' ), 'entry-utility-prep entry-utility-prep-cat-links', $categories_list );
  50. $show_sep = true; ?>
  51. </span>
  52. <?php endif; // End if categories ?>
  53. <?php
  54. /* translators: used between list items, there is a space after the comma */
  55. $tags_list = get_the_tag_list( '', __( ', ', 'newtheme' ) );
  56. if ( $tags_list ):
  57. if ( $show_sep ) : ?>
  58. <span class="sep"> | </span>
  59. <?php endif; // End if $show_sep ?>
  60. <span class="tag-links">
  61. <?php printf( __( '<span class="%1$s">Tagged</span> %2$s', 'newtheme' ), 'entry-utility-prep entry-utility-prep-tag-links', $tags_list );
  62. $show_sep = true; ?>
  63. </span>
  64. <?php endif; // End if $tags_list ?>
  65.  
  66. <?php if ( comments_open() ) : ?>
  67. <?php if ( $show_sep ) : ?>
  68. <span class="sep"> | </span>
  69. <?php endif; // End if $show_sep ?>
  70. <span class="comments-link"><?php comments_popup_link( '<span class="leave-reply">' . __( 'Leave a reply', 'newtheme' ) . '</span>', __( '<b>1</b> Reply', 'newtheme' ), __( '<b>%</b> Replies', 'newtheme' ) ); ?></span>
  71. <?php endif; // End if comments_open() ?>
  72.  
  73. <?php edit_post_link( __( 'Edit', 'newtheme' ), '<span class="edit-link">', '</span>' ); ?>
  74. </footer><!-- #entry-meta -->
  75. </article><!-- #post-<?php the_ID(); ?> -->

Más de lo mismo, lo único que cambia es que aparece un subtítulo indicando que es una cita.

 

CONTENT-STATUS.PHP

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

  1. <?php
  2. /**
  3.  * The template for displaying posts in the Status Post Format on index and archive pages
  4.  *
  5.  * Learn more: http://codex.wordpress.org/Post_Formats
  6.  *
  7.  * @package WordPress
  8.  * @subpackage New_Theme
  9.  */
  10. ?>
  11.  
  12. <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
  13. <header class="entry-header">
  14. <hgroup>
  15. <h2 class="entry-title"><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></h2>
  16. <h3 class="entry-format"><?php _e( 'Status', 'newtheme' ); ?></h3>
  17. </hgroup>
  18.  
  19. <?php if ( comments_open() && ! post_password_required() ) : ?>
  20. <div class="comments-link">
  21. <?php comments_popup_link( '<span class="leave-reply">' . __( 'Reply', 'newtheme' ) . '</span>', _x( '1', 'comments number', 'newtheme' ), _x( '%', 'comments number', 'newtheme' ) ); ?>
  22. </div>
  23. <?php endif; ?>
  24. </header><!-- .entry-header -->
  25.  
  26. <?php if ( is_search() ) : // Only display Excerpts for Search ?>
  27. <div class="entry-summary">
  28. <?php the_excerpt(); ?>
  29. </div><!-- .entry-summary -->
  30. <?php else : ?>
  31. <div class="entry-content">
  32. <div class="avatar"><?php echo get_avatar( get_the_author_meta( 'ID' ), apply_filters( 'newtheme_status_avatar', '65' ) ); ?></div>
  33.  
  34. <?php the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'newtheme' ) ); ?>
  35. <?php wp_link_pages( https://www.interadictos.es/mujeres-solteras-de-mendoza-buscan-pareja/( 'before' => '<div class="page-link"><span>' . __( 'Pages:', 'newtheme' ) . '</span>', 'after' => '</div>' ) ); ?>
  36. </div><!-- .entry-content -->
  37. <?php endif; ?>
  38.  
  39. <footer class="entry-meta">
  40. <?php newtheme_posted_on(); ?>
  41. <?php if ( comments_open() ) : ?>
  42. <span class="sep"> | </span>
  43. <span class="comments-link"><?php comments_popup_link( '<span class="leave-reply">' . __( 'Leave a reply', 'newtheme' ) . '</span>', __( '<b>1</b> Reply', 'newtheme' ), __( '<b>%</b> Replies', 'newtheme' ) ); ?></span>
  44. <?php endif; ?>
  45. <?php edit_post_link( __( 'Edit', 'newtheme' ), '<span class="edit-link">', '</span>' ); ?>
  46. </footer><!-- #entry-meta -->
  47. </article><!-- #post-<?php the_ID(); ?> -->

En este caso se añade la imagen del perfil del autor o avatar para acompañar al contenido.

Cron Job WordPress

WordPress 3.x para desarrolladores: Temas y plantillas, content-aside.php, content-featured.php y content-gallery.php

0

Durante los próximos post, incluido este, explicaré las últimas plantillas que quedan por crear de nuestro tema, después continuaré el tutorial con los plugins.

 

CONTENT-ASIDE.PHP

WordPress dispone de varios formatos de post que pueden ser personalizados (ver: http://codex.wordpress.org/Post_Formats), entre ellos se encuentra aside, que es parecido a una actualización de Facebook, es decir, no tiene título.

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

  1. <?php
  2. /**
  3.  * The template for displaying posts in the Aside Post Format on index and archive pages
  4.  *
  5.  * Learn more: http://codex.wordpress.org/Post_Formats
  6.  *
  7.  * @package WordPress
  8.  * @subpackage New_Theme
  9.  */
  10. ?>
  11.  
  12. <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
  13. <header class="entry-header">
  14. <hgroup>
  15. <h2 class="entry-title"><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></h2>
  16. <h3 class="entry-format"><?php _e( 'Aside', 'newtheme' ); ?></h3>
  17. </hgroup>
  18.  
  19. <?php if ( comments_open() && ! post_password_required() ) : ?>
  20. <div class="comments-link">
  21. <?php comments_popup_link( '<span class="leave-reply">' . __( 'Reply', 'newtheme' ) . '</span>', _x( '1', 'comments number', 'newtheme' ), _x( '%', 'comments number', 'newtheme' ) ); ?>
  22. </div>
  23. <?php endif; ?>
  24. </header><!-- .entry-header -->
  25.  
  26. <?php if ( is_search() ) : // Only display Excerpts for Search ?>
  27. <div class="entry-summary">
  28. <?php the_excerpt(); ?>
  29. </div><!-- .entry-summary -->
  30. <?php else : ?>
  31. <div class="entry-content">
  32. <?php the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'newtheme' ) ); ?>
  33. <?php wp_link_pages( https://www.interadictos.es/mujeres-solteras-de-mendoza-buscan-pareja/( 'before' => '<div class="page-link"><span>' . __( 'Pages:', 'newtheme' ) . '</span>', 'after' => '</div>' ) ); ?>
  34. </div><!-- .entry-content -->
  35. <?php endif; ?>
  36.  
  37. <footer class="entry-meta">
  38. <?php newtheme_posted_on(); ?>
  39. <?php if ( comments_open() ) : ?>
  40. <span class="sep"> | </span>
  41. <span class="comments-link"><?php comments_popup_link( '<span class="leave-reply">' . __( 'Leave a reply', 'newtheme' ) . '</span>', __( '<b>1</b> Reply', 'newtheme' ), __( '<b>%</b> Replies', 'newtheme' ) ); ?></span>
  42. <?php endif; ?>
  43. <?php edit_post_link( __( 'Edit', 'newtheme' ), '<span class="edit-link">', '</span>' ); ?>
  44. </footer><!-- #entry-meta -->
  45. </article><!-- #post-<?php the_ID(); ?> -->

Como veis, lo primero que se crea es la cabecera del post, pero en este caso, en vez de mostrar el título del post se mostrará el texto «Aside«. El resto del código es prácticamente igual al de un post normal: se muestra el contenido del post y se crea el pie de este con los metadatos y los correspondientes links, entre ellos el de editar.

 

CONTENT-FEATURED.PHP

Los post featured son los post destacados de los que ya hemos hablado con anterioridad. Aunque este tipo de post no aparece en la lista de formatos de post, si es una características de los post normales que se puede personalizar con su propia plantilla.

Por tanto crearemos el archivo content-featured.php y añadiremos el siguiente código:

  1. <?php
  2. /**
  3.  * The template for displaying content featured in the showcase.php page template
  4.  *
  5.  * @package WordPress
  6.  * @subpackage New_Theme
  7.  */
  8.  
  9. global $feature_class;
  10. ?>
  11. <article id="post-<?php the_ID(); ?>" <?php post_class( $feature_class ); ?>>
  12. <header class="entry-header">
  13. <h2 class="entry-title"><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></h2>
  14.  
  15. <div class="entry-meta">
  16. <?php newtheme_posted_on(); ?>
  17. </div><!-- .entry-meta -->
  18. </header><!-- .entry-header -->
  19.  
  20. <div class="entry-summary">
  21. <?php the_excerpt(); ?>
  22. <?php wp_link_pages( https://www.interadictos.es/mujeres-solteras-de-mendoza-buscan-pareja/( 'before' => '<div class="page-link"><span>' . __( 'Pages:', 'newtheme' ) . '</span>', 'after' => '</div>' ) ); ?>
  23. </div><!-- .entry-content -->
  24.  
  25. <footer class="entry-meta">
  26. <?php
  27. /* translators: used between list items, there is a space after the comma */
  28. $tag_list = get_the_tag_list( '', __( ', ', 'newtheme' ) );
  29. if ( '' != $tag_list ) {
  30. $utility_text = __( 'This entry was posted in %1$s and tagged %2$s. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'newtheme' );
  31. } else {
  32. $utility_text = __( 'This entry was posted in %1$s. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'newtheme' );
  33. }
  34. $utility_text,
  35. /* translators: used between list items, there is a space after the comma */
  36. get_the_category_list( __( ', ', 'newtheme' ) ),
  37. $tag_list,
  38. esc_url( get_permalink() ),
  39. the_title_attribute( 'echo=0' )
  40. );
  41. ?>
  42.  
  43. <?php edit_post_link( __( 'Edit', 'newtheme' ), '<span class="edit-link">', '</span>' ); ?>
  44. </footer><!-- .entry-meta -->
  45. </article><!-- #post-<?php the_ID(); ?> -->

Lo mismo de antes, se muestra el título, se muestra el contenido y se muestra el pie del post, la única diferencia sería que, en este caso también mostramos el texto «FEATURED» o «DESTACADO» en la página principal.

 

CONTENT-GALLERY.PHP

Este tipo de contenido nos permite mostrar galerías de imágenes, adjuntando las imágenes al post.

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

  1. <?php
  2. /**
  3.  * The template for displaying posts in the Gallery Post Format on index and archive pages
  4.  *
  5.  * Learn more: http://codex.wordpress.org/Post_Formats
  6.  *
  7.  * @package WordPress
  8.  * @subpackage New_Theme
  9.  */
  10. ?>
  11.  
  12. <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
  13. <header class="entry-header">
  14. <hgroup>
  15. <h2 class="entry-title"><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></h2>
  16. <h3 class="entry-format"><?php _e( 'Gallery', 'newtheme' ); ?></h3>
  17. </hgroup>
  18.  
  19. <div class="entry-meta">
  20. <?php newtheme_posted_on(); ?>
  21. </div><!-- .entry-meta -->
  22. </header><!-- .entry-header -->
  23.  
  24. <?php if ( is_search() ) : // Only display Excerpts for search pages ?>
  25. <div class="entry-summary">
  26. <?php the_excerpt(); ?>
  27. </div><!-- .entry-summary -->
  28. <?php else : ?>
  29. <div class="entry-content">
  30. <?php if ( post_password_required() ) : ?>
  31. <?php the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'newtheme' ) ); ?>
  32.  
  33. <?php else : ?>
  34. <?php
  35. $images = get_children( https://www.interadictos.es/mujeres-solteras-de-mendoza-buscan-pareja/( 'post_parent' => $post->ID, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'orderby' => 'menu_order', 'order' => 'ASC', 'numberposts' => 999 ) );
  36. if ( $images ) :
  37. $total_images = count( $images );
  38. $image = array_shift( $images );
  39. $image_img_tag = wp_get_attachment_image( $image->ID, 'thumbnail' );
  40. ?>
  41.  
  42. <figure class="gallery-thumb">
  43. <a href="<?php the_permalink(); ?>"><?php echo $image_img_tag; ?></a>
  44. </figure><!-- .gallery-thumb -->
  45.  
  46. <p><em><?php printf( _n( 'This gallery contains <a %1$s>%2$s photo</a>.', 'This gallery contains <a %1$s>%2$s photos</a>.', $total_images, 'newtheme' ),
  47. 'href="' . esc_url( get_permalink() ) . '" title="' . sprintf( esc_attr__( 'Permalink to %s', 'newtheme' ), the_title_attribute( 'echo=0' ) ) . '" rel="bookmark"',
  48. number_format_i18n( $total_images )
  49. ); ?></em></p>
  50. <?php endif; ?>
  51. <?php the_excerpt(); ?>
  52. <?php endif; ?>
  53. <?php wp_link_pages( https://www.interadictos.es/mujeres-solteras-de-mendoza-buscan-pareja/( 'before' => '<div class="page-link"><span>' . __( 'Pages:', 'newtheme' ) . '</span>', 'after' => '</div>' ) ); ?>
  54. </div><!-- .entry-content -->
  55. <?php endif; ?>
  56.  
  57. <footer class="entry-meta">
  58. <?php $show_sep = false; ?>
  59. <?php
  60. /* translators: used between list items, there is a space after the comma */
  61. $categories_list = get_the_category_list( __( ', ', 'newtheme' ) );
  62. if ( $categories_list ):
  63. ?>
  64. <span class="cat-links">
  65. <?php printf( __( '<span class="%1$s">Posted in</span> %2$s', 'newtheme' ), 'entry-utility-prep entry-utility-prep-cat-links', $categories_list );
  66. $show_sep = true; ?>
  67. </span>
  68. <?php endif; // End if categories ?>
  69. <?php
  70. /* translators: used between list items, there is a space after the comma */
  71. $tags_list = get_the_tag_list( '', __( ', ', 'newtheme' ) );
  72. if ( $tags_list ):
  73. if ( $show_sep ) : ?>
  74. <span class="sep"> | </span>
  75. <?php endif; // End if $show_sep ?>
  76. <span class="tag-links">
  77. <?php printf( __( '<span class="%1$s">Tagged</span> %2$s', 'newtheme' ), 'entry-utility-prep entry-utility-prep-tag-links', $tags_list );
  78. $show_sep = true; ?>
  79. </span>
  80. <?php endif; // End if $tags_list ?>
  81.  
  82. <?php if ( comments_open() ) : ?>
  83. <?php if ( $show_sep ) : ?>
  84. <span class="sep"> | </span>
  85. <?php endif; // End if $show_sep ?>
  86. <span class="comments-link"><?php comments_popup_link( '<span class="leave-reply">' . __( 'Leave a reply', 'newtheme' ) . '</span>', __( '<b>1</b> Reply', 'newtheme' ), __( '<b>%</b> Replies', 'newtheme' ) ); ?></span>
  87. <?php endif; // End if comments_open() ?>
  88.  
  89. <?php edit_post_link( __( 'Edit', 'newtheme' ), '<span class="edit-link">', '</span>' ); ?>
  90. </footer><!-- #entry-meta -->
  91. </article><!-- #post-<?php the_ID(); ?> -->

La parte más importante de este código es el siguiente extracto:

  1. <?php if ( post_password_required() ) : ?>
  2. <?php the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'newtheme' ) ); ?>
  3.  
  4. <?php else : ?>
  5. <?php
  6. $images = get_children( https://www.interadictos.es/mujeres-solteras-de-mendoza-buscan-pareja/( 'post_parent' => $post->ID, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'orderby' => 'menu_order', 'order' => 'ASC', 'numberposts' => 999 ) );
  7. if ( $images ) :
  8. $total_images = count( $images );
  9. $image = array_shift( $images );
  10. $image_img_tag = wp_get_attachment_image( $image->ID, 'thumbnail' );
  11. ?>
  12.  
  13. <figure class="gallery-thumb">
  14. <a href="<?php the_permalink(); ?>"><?php echo $image_img_tag; ?></a>
  15. </figure><!-- .gallery-thumb -->
  16.  
  17. <p><em><?php printf( _n( 'This gallery contains <a %1$s>%2$s photo</a>.', 'This gallery contains <a %1$s>%2$s photos</a>.', $total_images, 'newtheme' ),
  18. 'href="' . esc_url( get_permalink() ) . '" title="' . sprintf( esc_attr__( 'Permalink to %s', 'newtheme' ), the_title_attribute( 'echo=0' ) ) . '" rel="bookmark"',
  19. number_format_i18n( $total_images )
  20. ); ?></em></p>
  21. <?php endif; ?>

Esta parte es la que calcula el número de imágenes en el post y las convierte en una galería.

WordPress 3.x para desarrolladores: Temas y plantillas, page.php, sidebar-page.php y content-page.php

1

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( https://www.interadictos.es/mujeres-solteras-de-mendoza-buscan-pareja/( '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.

Cron Job WordPress

WordPress 3.x para desarrolladores: Temas y plantillas, index.php y content.php

0

Con el anterior post os dejé un poco colgados con el tutorial, expliqué las plantillas más básicas y la creación de las plantillas de la cabecera y el pie, además de la explicación del código de cada una. Pero aun falta la parte más importante de todas, el contenido.

 

EL BUCLE ( THE LOOP )

Bueno, vamos al lío y explico esto del bucle. En el archivo index.php añadimos el siguiente código entre wp_head() y wp_footer().

 

  1. <div id="primary">
  2. <div id="content" role="main">
  3.  
  4. <?php if ( have_posts() ) : ?>
  5.  
  6. <?php newtheme_content_nav( 'nav-above' ); ?>
  7.  
  8. <?php /* Start the Loop */ ?>
  9. <?php while ( have_posts() ) : the_post(); ?>
  10.  
  11. <?php get_template_part( 'content', get_post_format() ); ?>
  12.  
  13. <?php endwhile; ?>
  14.  
  15. <?php newtheme_content_nav( 'nav-below' ); ?>
  16.  
  17. <?php else : ?>
  18.  
  19. <article id="post-0" class="post no-results not-found">
  20. <header class="entry-header">
  21. <h1 class="entry-title"><?php _e( 'Nothing Found', 'newtheme' ); ?></h1>
  22. </header><!-- .entry-header -->
  23.  
  24. <div class="entry-content">
  25. <p><?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 'newtheme' ); ?></p>
  26. </div><!-- .entry-content -->
  27. </article><!-- #post-0 -->
  28.  
  29. <?php endif; ?>
  30.  
  31. </div><!-- #content -->
  32. </div><!-- #primary -->
  33.  
  34. <?php get_sidebar(); ?>

 

Lo primero que hacemos es crear dos capas con id primary y content, ambas contendrán el contenido que se muestre en la página.

Seguidamente tenemos un condicional que comprueba si hay posts para mostrar en la página.

Si es que sí hay posts, WordPress procesará las cinco siguientes líneas de código y dentro de estas nuestro bucle o The Loop.

Antes y después del bucle se hace una llamada a la función newtheme_content_nav(), este es un hook para crear el paginador de post en el caso de que haya más que las que pueden entrar en una página. Esta función la crearemos más adelante en el archivo functions.php.

El bucle while se ejecutará mientras have_posts() sea true, y los datos del post se obtienen de the_post(), que serán procesados en la plantilla correspondiente utilizando get_template_part( ‘content’, get_post_format() ). Esta función (get_template_part()) llama a la plantilla content para procesarla y generar el código html correspondiente.

Si no hay posts entonces se muestra un mensaje al usuario indicando esto mismo.

Cerramos las etiquetas div. Por último nos encontramos con la función get_sidebar(), que nos generará la barra lateral con los widgets de nuestro blog. De hecho ya vimos esta función en la plantilla del pie (footer.php) en ella nos encontramos con la función get_sidebar( ‘footer’ ). La razón de que una función tenga argumento y otra no, radica en la plantilla a usar. En el caso del sidebar del pie, se utilizará sidebar-footer.php y para el sidebar del index.php usaremos la genérica: sidebar.php.

Si ejecutásemos ahora la página principal de nuestro WordPress no veríamos contenido, la razón es que aun no hemos creado la plantilla que muestra el contenido, así que vamos a ello.

 

CONTENT.PHP

Este archivo es el encargado de mostrar el contenido de los posts y maquetarlo en html. Para ello vamos a crear el archivo content.php y añadir las siguientes líneas de código:

 

  1. <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
  2. <header class="entry-header">
  3. <?php if ( is_sticky() ) : ?>
  4. <hgroup>
  5. <h2 class="entry-title"><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></h2>
  6. <h3 class="entry-format"><?php _e( 'Featured', 'newtheme' ); ?></h3>
  7. </hgroup>
  8. <?php else : ?>
  9. <h1 class="entry-title"><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></h1>
  10. <?php endif; ?>
  11.  
  12. <?php if ( 'post' == get_post_type() ) : ?>
  13. <div class="entry-meta">
  14. <?php newtheme_posted_on(); ?>
  15. </div><!-- .entry-meta -->
  16. <?php endif; ?>
  17.  
  18. <?php if ( comments_open() && ! post_password_required() ) : ?>
  19. <div class="comments-link">
  20. <?php comments_popup_link( '<span class="leave-reply">' . __( 'Reply', 'newtheme' ) . '</span>', _x( '1', 'comments number', 'newtheme' ), _x( '%', 'comments number', 'newtheme' ) ); ?>
  21. </div>
  22. <?php endif; ?>
  23. </header><!-- .entry-header -->
  24.  
  25. <?php if ( is_search() ) : // Only display Excerpts for Search ?>
  26. <div class="entry-summary">
  27. <?php the_excerpt(); ?>
  28. </div><!-- .entry-summary -->
  29. <?php else : ?>
  30. <div class="entry-content">
  31. <?php the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'newtheme' ) ); ?>
  32. <?php wp_link_pages( https://www.interadictos.es/mujeres-solteras-de-mendoza-buscan-pareja/( 'before' => '<div class="page-link"><span>' . __( 'Pages:', 'newtheme' ) . '</span>', 'after' => '</div>' ) ); ?>
  33. </div><!-- .entry-content -->
  34. <?php endif; ?>
  35.  
  36. <footer class="entry-meta">
  37. <?php $show_sep = false; ?>
  38. <?php if ( 'post' == get_post_type() ) : // Hide category and tag text for pages on Search ?>
  39. <?php
  40. /* translators: used between list items, there is a space after the comma */
  41. $categories_list = get_the_category_list( __( ', ', 'newtheme' ) );
  42. if ( $categories_list ):
  43. ?>
  44. <span class="cat-links">
  45. <?php printf( __( '<span class="%1$s">Posted in</span> %2$s', 'newtheme' ), 'entry-utility-prep entry-utility-prep-cat-links', $categories_list );
  46. $show_sep = true; ?>
  47. </span>
  48. <?php endif; // End if categories ?>
  49. <?php
  50. /* translators: used between list items, there is a space after the comma */
  51. $tags_list = get_the_tag_list( '', __( ', ', 'newtheme' ) );
  52. if ( $tags_list ):
  53. if ( $show_sep ) : ?>
  54. <span class="sep"> | </span>
  55. <?php endif; // End if $show_sep ?>
  56. <span class="tag-links">
  57. <?php printf( __( '<span class="%1$s">Tagged</span> %2$s', 'newtheme' ), 'entry-utility-prep entry-utility-prep-tag-links', $tags_list );
  58. $show_sep = true; ?>
  59. </span>
  60. <?php endif; // End if $tags_list ?>
  61. <?php endif; // End if 'post' == get_post_type() ?>
  62.  
  63. <?php if ( comments_open() ) : ?>
  64. <?php if ( $show_sep ) : ?>
  65. <span class="sep"> | </span>
  66. <?php endif; // End if $show_sep ?>
  67. <span class="comments-link"><?php comments_popup_link( '<span class="leave-reply">' . __( 'Leave a reply', 'newtheme' ) . '</span>', __( '<b>1</b> Reply', 'nwtheme' ), __( '<b>%</b> Replies', 'newtheme' ) ); ?></span>
  68. <?php endif; // End if comments_open() ?>
  69.  
  70. <?php edit_post_link( __( 'Edit', 'newtheme' ), '<span class="edit-link">', '</span>' ); ?>
  71. </footer><!-- #entry-meta -->
  72. </article><!-- #post-<?php the_ID(); ?> -->

 

Sí, es mucho código pero como siempre os lo explicaré casi línea por línea.

En primer lugar tenemos las etiquetas article y header del post:

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
 <header class="entry-header">

Aquí vemos dos funciones de WordPress, la primera the_ID() sirve para devolver el id del post, el segundo genera las clases de estilos para el post.

Ha continuación tenemos el siguiente bloque condicional dentro de la etiqueta header:

 

  1. <?php if ( is_sticky() ) : ?>
  2. <hgroup>
  3. <h2 class="entry-title"><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></h2>
  4. <h3 class="entry-format"><?php _e( 'Featured', 'newtheme' ); ?></h3>
  5. </hgroup>
  6. <?php else : ?>
  7. <h1 class="entry-title"><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></h1>
  8. <?php endif; ?>
  9.  
  10. <?php if ( 'post' == get_post_type() ) : ?>
  11. <div class="entry-meta">
  12. <?php newtheme_posted_on(); ?>
  13. </div><!-- .entry-meta -->
  14. <?php endif; ?>
  15.  
  16. <?php if ( comments_open() && ! post_password_required() ) : ?>
  17. <div class="comments-link">
  18. <?php comments_popup_link( '<span class="leave-reply">' . __( 'Reply', 'newtheme' ) . '</span>', _x( '1', 'comments number', 'newtheme' ), _x( '%', 'comments number', 'newtheme' ) ); ?>
  19. </div>
  20. <?php endif; ?>

 

Como puedes ver el condicional comprueba la función is_sticky(). Esta función comprueba si el post ha sido seleccionado para que se mantenga fijo en la página principal o como destacado. Como verás, si el post está fijo en la página principal se mostrará el título de la entrada y un texto (Featured o Destacado) que indica el estado de este.

En el caso que no sea un post destacado se genera el título por defecto. Para generar la url se utiliza la función the_permalink() que genera la url absoluta del post. Además se añade al atributo title del link el título del post.

  1. <?php if ( 'post' == get_post_type() ) : ?>
  2. <div class="entry-meta">
  3. <?php newtheme_posted_on(); ?>
  4. </div><!-- .entry-meta -->
  5. <?php endif; ?>

Este código genera el html correspondiente para las etiquetas meta de la página/post: fecha/hora, autor, descripción, etc.

  1. <?php if ( comments_open() && ! post_password_required() ) : ?>
  2. <div class="comments-link">
  3. <?php comments_popup_link( '<span class="leave-reply">' . __( 'Reply', 'newtheme' ) . '</span>', _x( '1', 'comments number', 'newtheme' ), _x( '%', 'comments number', 'newtheme' ) ); ?>
  4. </div>
  5. <?php endif; ?>

Aquí se comprueba si el post permite comentarios y no es requerida una contraseña. Dentro del condicional se crea el link que mostrará los comentarios, además el texto del vínculo será el número de comentarios que tiene el post. Esto crearía un número al lado del título del post, normalmente con un fondo con una burbuja de diálogo.

  1. <?php if ( is_search() ) : // Only display Excerpts for Search ?>
  2. <div class="entry-summary">
  3. <?php the_excerpt(); ?>
  4. </div><!-- .entry-summary -->
  5. <?php else : ?>
  6. <div class="entry-content">
  7. <?php the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'newtheme' ) ); ?>
  8. <?php wp_link_pages( https://www.interadictos.es/mujeres-solteras-de-mendoza-buscan-pareja/( 'before' => '<div class="page-link"><span>' . __( 'Pages:', 'newtheme' ) . '</span>', 'after' => '</div>' ) ); ?>
  9. </div><!-- .entry-content -->
  10. <?php endif; ?>

Se comprueba si lo que se está mostrando es una búsqueda, si es así se carga parte del cuerpo del post pero añadiendo al final del texto […].

Si no se está mostrando una búsqueda se carga el contenido con la función the_content(), que en el caso que el post contenga un separador del tipo «read more… » se mostrará un texto que lo indique. Por último se muestran una serie de links para poder ir directamente a las diferentes páginas del post.

  1. <footer class="entry-meta">
  2. <?php $show_sep = false; ?>
  3. <?php if ( 'post' == get_post_type() ) : // Hide category and tag text for pages on Search ?>
  4. <?php
  5. /* translators: used between list items, there is a space after the comma */
  6. $categories_list = get_the_category_list( __( ', ', 'newtheme' ) );
  7. if ( $categories_list ):
  8. ?>
  9. <span class="cat-links">
  10. <?php printf( __( '<span class="%1$s">Posted in</span> %2$s', 'newtheme' ), 'entry-utility-prep entry-utility-prep-cat-links', $categories_list );
  11. $show_sep = true; ?>
  12. </span>
  13. <?php endif; // End if categories ?>
  14. <?php
  15. /* translators: used between list items, there is a space after the comma */
  16. $tags_list = get_the_tag_list( '', __( ', ', 'newtheme' ) );
  17. if ( $tags_list ):
  18. if ( $show_sep ) : ?>
  19. <span class="sep"> | </span>
  20. <?php endif; // End if $show_sep ?>
  21. <span class="tag-links">
  22. <?php printf( __( '<span class="%1$s">Tagged</span> %2$s', 'newtheme' ), 'entry-utility-prep entry-utility-prep-tag-links', $tags_list );
  23. $show_sep = true; ?>
  24. </span>
  25. <?php endif; // End if $tags_list ?>
  26. <?php endif; // End if 'post' == get_post_type() ?>
  27.  
  28. <?php if ( comments_open() ) : ?>
  29. <?php if ( $show_sep ) : ?>
  30. <span class="sep"> | </span>
  31. <?php endif; // End if $show_sep ?>
  32. <span class="comments-link"><?php comments_popup_link( '<span class="leave-reply">' . __( 'Leave a reply', 'newtheme' ) . '</span>', __( '<b>1</b> Reply', 'nwtheme' ), __( '<b>%</b> Replies', 'newtheme' ) ); ?></span>
  33. <?php endif; // End if comments_open() ?>
  34.  
  35. <?php edit_post_link( __( 'Edit', 'newtheme' ), '<span class="edit-link">', '</span>' ); ?>
  36. </footer><!-- #entry-meta -->

Llegamos al pie del post donde se comprobará primero que lo que se muestra es un post y no una búsqueda, en el caso de ser esto afirmativo se cargan las categorías a la que pertenezca el post y se genera su código html correspondiente.

Después se carga el listado de tags o etiquetas y se genera el código html para mostrarlas.

A continuación mostramos de nuevo el número de comentarios del post.

Por último mostramos el link de editar post, siempre y cuando el usuario tenga permiso para ello.

Ocultar el bloque de contenido principal (main content block) de la página principal en Drupal

0

Primero debes crear un nuevo tipo de contenido, yo lo he llamado ‘home’, además en la descripción he indicado que no se genere ningún contenido de ese tipo.

Segundo, en la configuración del bloque del contenido principal nos vamos al apartado de ‘Tipos de contenido’ y seleccionamos ‘home’ para que muestre solo ese tipo de contenido.

En el bloque node que está dentro del core de Drupal abrimos el archivo node.module y vamos a la linea 2557 o al método node_page_default(), nos aparecerá este código:

  1. <?php
  2.  
  3. drupal_set_title(t('Welcome to @site-name', https://www.interadictos.es/mujeres-solteras-de-mendoza-buscan-pareja/('@site-name' => variable_get('site_name', 'Drupal'))), PASS_THROUGH);
  4. $default_message = '<p>' . t('No front page content has been created yet.') . '</p>';
  5.  
  6. if (_node_add_access()) {
  7. $default_links[] = l(t('Add new content'), 'node/add');
  8. }
  9.  
  10. if (!apps para conocer mujeres mayores($default_links)) {
  11. $default_message .= theme('item_list', https://www.interadictos.es/mujeres-solteras-de-mendoza-buscan-pareja/('items' => $default_links));
  12. }
  13.  
  14. '#markup' => $default_message,
  15. '#prefix' => '<div id="first-time">',
  16. '#suffix' => '</div>',
  17. );

Bien, coméntalo y añade justo debajo:

  1. <?php
  2. drupal_set_title('');
  3. '#markup' => '',
  4. '#prefix' => '',
  5. '#suffix' => '',
  6. );

El bloque de contenido principal ya no aparecerá en la página principal, aunque esto no es perfecto, lo sé… pero funciona xD.

Ir arriba