Estas en: Home > author

Entradas etiquetadas con author

Gráfico de datos estructurados

Corregir los errores de microformatos en WordPress

0

Como ya os comente en otro post, estoy haciendo una actualización del tema Mystique, el cual lleva sin actualizarse cerca de dos años. Esto me ha llevado a descubrir algunos fallos en el tema que hay que corregir. Uno de ellos es un problema con los microformatos.

Al utilizar la herramienta para Webmaster de Google, en la sección «Aspecto de la búsqueda«, apartado «Datos estructurados» nos aparecerá algo como lo de la siguiente imagen:

Gráfico de datos estructurados

Gráfico de datos estructurados

Continue reading “Corregir los errores de microformatos en WordPress” »

Cron Job WordPress

WordPress 3.x para desarrolladores: Temas y plantillas, category.php, author.php, archive.php y 404.php

0

Estas son las últimas plantillas que crearemos para nuestro tema.

 

CATEGORY.PHP

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

  1. <?php
  2. /**
  3.  * The template for displaying Category 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( __( 'Category Archives: %s', 'newtheme' ), '<span>' . single_cat_title( '', false ) . '</span>' );
  19. ?></h1>
  20.  
  21. <?php
  22. $category_description = category_description();
  23. if ( ! empty( $category_description ) )
  24. echo apply_filters( 'category_archive_meta', '<div class="category-archive-meta">' . $category_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(); ?>

Esta plantilla está creada para mostrar los post que están en una misma categoría. La estructura de la página es idéntica al del resto que hemos visto del estilo.

 

AUTHOR.PHP

Creamos el archivo author-php y añadimos el siguiente código:

  1. <?php
  2. /**
  3.  * The template for displaying Author 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. <?php
  17. /* Queue the first post, that way we know
  18. * what author we're dealing with (if that is the case).
  19. *
  20. * We reset this later so we can run the loop
  21. * properly with a call to rewind_posts().
  22. */
  23. the_post();
  24. ?>
  25.  
  26. <header class="page-header">
  27. <h1 class="page-title author"><?php printf( __( 'Author Archives: %s', 'newtheme' ), '<span class="vcard"><a class="url fn n" href="' . esc_url( get_author_posts_url( get_the_author_meta( "ID" ) ) ) . '" title="' . esc_attr( get_the_author() ) . '" rel="me">' . get_the_author() . '</a></span>' ); ?></h1>
  28. </header>
  29.  
  30. <?php
  31. /* Since we called the_post() above, we need to
  32. * rewind the loop back to the beginning that way
  33. * we can run the loop properly, in full.
  34. */
  35. rewind_posts();
  36. ?>
  37.  
  38. <?php newtheme_content_nav( 'nav-above' ); ?>
  39.  
  40. <?php
  41. // If a user has filled out their description, show a bio on their entries.
  42. if ( get_the_author_meta( 'description' ) ) : ?>
  43. <div id="author-info">
  44. <div id="author-avatar">
  45. <?php echo get_avatar( get_the_author_meta( 'user_email' ), apply_filters( 'newtheme_author_bio_avatar_size', 60 ) ); ?>
  46. </div><!-- #author-avatar -->
  47. <div id="author-description">
  48. <h2><?php printf( __( 'About %s', 'newtheme' ), get_the_author() ); ?></h2>
  49. <?php the_author_meta( 'description' ); ?>
  50. </div><!-- #author-description -->
  51. </div><!-- #author-info -->
  52. <?php endif; ?>
  53.  
  54. <?php /* Start the Loop */ ?>
  55. <?php while ( have_posts() ) : the_post(); ?>
  56.  
  57. <?php
  58. /* Include the Post-Format-specific template for the content.
  59. * If you want to overload this in a child theme then include a file
  60. * called content-___.php (where ___ is the Post Format name) and that will be used instead.
  61. */
  62. get_template_part( 'content', get_post_format() );
  63. ?>
  64.  
  65. <?php endwhile; ?>
  66.  
  67. <?php newtheme_content_nav( 'nav-below' ); ?>
  68.  
  69. <?php else : ?>
  70.  
  71. <article id="post-0" class="post no-results not-found">
  72. <header class="entry-header">
  73. <h1 class="entry-title"><?php _e( 'Nothing Found', 'newtheme' ); ?></h1>
  74. </header><!-- .entry-header -->
  75.  
  76. <div class="entry-content">
  77. <p><?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 'newtheme' ); ?></p>
  78. <?php get_search_form(); ?>
  79. </div><!-- .entry-content -->
  80. </article><!-- #post-0 -->
  81.  
  82. <?php endif; ?>
  83.  
  84. </div><!-- #content -->
  85. </section><!-- #primary -->
  86.  
  87. <?php get_sidebar(); ?>
  88. <?php get_footer(); ?>

Esta plantilla muestra los post que un autor haya escrito. Lo más relevante del código es que para obtener los datos del autor se recupera el primer post, se genera la cabecera del contenido y después se reinicia el dataset para mostrar los post desde el primero, utilizando para ello la función rewind_posts().

 

ARCHIVE.PHP

Creamos el archivo archive.php y añadimos el siguiete código:

  1. <?php
  2. /**
  3.  * The template for displaying Archive pages.
  4.  *
  5.  * Used to display archive-type pages if nothing more specific matches a query.
  6.  * For example, puts together date-based pages if no date.php file exists.
  7.  *
  8.  * Learn more: http://codex.wordpress.org/Template_Hierarchy
  9.  *
  10.  * @package WordPress
  11.  * @subpackage Twenty_Eleven
  12.  */
  13.  
  14. get_header(); ?>
  15.  
  16. <section id="primary">
  17. <div id="content" role="main">
  18.  
  19. <?php if ( have_posts() ) : ?>
  20.  
  21. <header class="page-header">
  22. <h1 class="page-title">
  23. <?php if ( is_day() ) : ?>
  24. <?php printf( __( 'Daily Archives: %s', 'newtheme' ), '<span>' . get_the_date() . '</span>' ); ?>
  25. <?php elseif ( is_month() ) : ?>
  26. <?php printf( __( 'Monthly Archives: %s', 'newtheme' ), '<span>' . get_the_date( _x( 'F Y', 'monthly archives date format', 'newtheme' ) ) . '</span>' ); ?>
  27. <?php elseif ( is_year() ) : ?>
  28. <?php printf( __( 'Yearly Archives: %s', 'newtheme' ), '<span>' . get_the_date( _x( 'Y', 'yearly archives date format', 'newtheme' ) ) . '</span>' ); ?>
  29. <?php else : ?>
  30. <?php _e( 'Blog Archives', 'newtheme' ); ?>
  31. <?php endif; ?>
  32. </h1>
  33. </header>
  34.  
  35. <?php newtheme_content_nav( 'nav-above' ); ?>
  36.  
  37. <?php /* Start the Loop */ ?>
  38. <?php while ( have_posts() ) : the_post(); ?>
  39.  
  40. <?php
  41. /* Include the Post-Format-specific template for the content.
  42. * If you want to overload this in a child theme then include a file
  43. * called content-___.php (where ___ is the Post Format name) and that will be used instead.
  44. */
  45. get_template_part( 'content', get_post_format() );
  46. ?>
  47.  
  48. <?php endwhile; ?>
  49.  
  50. <?php newtheme_content_nav( 'nav-below' ); ?>
  51.  
  52. <?php else : ?>
  53.  
  54. <article id="post-0" class="post no-results not-found">
  55. <header class="entry-header">
  56. <h1 class="entry-title"><?php _e( 'Nothing Found', 'newtheme' ); ?></h1>
  57. </header><!-- .entry-header -->
  58.  
  59. <div class="entry-content">
  60. <p><?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 'newtheme' ); ?></p>
  61. <?php get_search_form(); ?>
  62. </div><!-- .entry-content -->
  63. </article><!-- #post-0 -->
  64.  
  65. <?php endif; ?>
  66.  
  67. </div><!-- #content -->
  68. </section><!-- #primary -->
  69.  
  70. <?php get_sidebar(); ?>
  71. <?php get_footer(); ?>

Esta plantilla muestra los post publicados en una fecha o entre fechas concretas.

Ir arriba