Permalink
Browse files

Add tag.php and category.php to Twenty Twelve. While by no means requ…

…ired, it pulls some extra logic out of archive.php, instead leveraging the template hierarchy so it is hopefully more understandable to users tweaking their themes. Use alternative control structure syntax in all templates. fixes #21951.

git-svn-id: http://core.svn.wordpress.org/trunk@22048 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information...
1 parent 97bfd2d commit 3d954a4b60944323d1644942be6c225b4935747b @nacin nacin committed Sep 27, 2012
@@ -6,7 +6,8 @@
* For example, puts together date-based pages if no date.php file exists.
*
* If you'd like to further customize these archive views, you may create a
- * new template file for each specific one, like tag.php for Tag archives or
+ * new template file for each specific one. For example, Twenty Twelve already
+ * has tag.php for Tag archives, category.php for Category archives, and
* author.php for Author archives.
*
* Learn more: http://codex.wordpress.org/Template_Hierarchy
@@ -24,35 +25,16 @@
<?php if ( have_posts() ) : ?>
<header class="archive-header">
<h1 class="archive-title"><?php
- if ( is_day() ) {
+ if ( is_day() ) :
printf( __( 'Daily Archives: %s', 'twentytwelve' ), '<span>' . get_the_date() . '</span>' );
- } elseif ( is_month() ) {
+ elseif ( is_month() ) :
printf( __( 'Monthly Archives: %s', 'twentytwelve' ), '<span>' . get_the_date( _x( 'F Y', 'monthly archives date format', 'twentytwelve' ) ) . '</span>' );
- } elseif ( is_year() ) {
+ elseif ( is_year() ) :
printf( __( 'Yearly Archives: %s', 'twentytwelve' ), '<span>' . get_the_date( _x( 'Y', 'yearly archives date format', 'twentytwelve' ) ) . '</span>' );
- } elseif ( is_tag() ) {
- printf( __( 'Tag Archives: %s', 'twentytwelve' ), '<span>' . single_tag_title( '', false ) . '</span>' );
- } elseif ( is_category() ) {
- printf( __( 'Category Archives: %s', 'twentytwelve' ), '<span>' . single_cat_title( '', false ) . '</span>' );
- } else {
+ else :
_e( 'Archives', 'twentytwelve' );
- }
+ endif;
?></h1>
-
- <?php
- // Show an optional tag description.
- if ( is_tag() ) {
- $tag_description = tag_description();
- if ( $tag_description )
- echo '<div class="archive-meta">' . $tag_description . '</div>';
- }
- // Show an optional category description.
- if ( is_category() ) {
- $category_description = category_description();
- if ( $category_description )
- echo '<div class="archive-meta">' . $category_description . '</div>';
- }
- ?>
</header><!-- .archive-header -->
<?php
@@ -2,6 +2,10 @@
/**
* The template for displaying Author Archive pages.
*
+ * Used to display archive-type pages for posts by an author.
+ *
+ * Learn more: http://codex.wordpress.org/Template_Hierarchy
+ *
* @package WordPress
* @subpackage Twenty_Twelve
* @since Twenty Twelve 1.0
@@ -0,0 +1,51 @@
+<?php
+/**
+ * The template for displaying Category pages.
+ *
+ * Used to display archive-type pages for posts in a category.
+ *
+ * Learn more: http://codex.wordpress.org/Template_Hierarchy
+ *
+ * @package WordPress
+ * @subpackage Twenty_Twelve
+ * @since Twenty Twelve 1.0
+ */
+
+get_header(); ?>
+
+ <section id="primary" class="site-content">
+ <div id="content" role="main">
+
+ <?php if ( have_posts() ) : ?>
+ <header class="archive-header">
+ <h1 class="archive-title"><?php printf( __( 'Category Archives: %s', 'twentytwelve' ), '<span>' . single_cat_title( '', false ) . '</span>' ); ?></h1>
+
+ <?php if ( category_description() ) : // Show an optional category description ?>
+ <div class="archive-meta"><?php echo category_description(); ?></div>
+ <?php endif; ?>
+ </header><!-- .archive-header -->
+
+ <?php
+ /* Start the Loop */
+ while ( have_posts() ) : the_post();
+
+ /* Include the post format-specific template for the content. If you want to
+ * this in a child theme then include a file called called content-___.php
+ * (where ___ is the post format) and that will be used instead.
+ */
+ get_template_part( 'content', get_post_format() );
+
+ endwhile;
+
+ twentytwelve_content_nav( 'nav-below' );
+ ?>
+
+ <?php else : ?>
+ <?php get_template_part( 'content', 'none' ); ?>
+ <?php endif; ?>
+
+ </div><!-- #content -->
+ </section><!-- #primary -->
+
+<?php get_sidebar(); ?>
+<?php get_footer(); ?>
@@ -2,6 +2,8 @@
/**
* The template for displaying image attachments.
*
+ * Learn more: http://codex.wordpress.org/Template_Hierarchy
+ *
* @package WordPress
* @subpackage Twenty_Twelve
* @since Twenty Twelve 1.0
@@ -51,23 +53,25 @@
* 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
*/
$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' ) ) );
-foreach ( $attachments as $k => $attachment ) {
+foreach ( $attachments as $k => $attachment ) :
if ( $attachment->ID == $post->ID )
break;
-}
+endforeach;
+
$k++;
// If there is more than 1 attachment in a gallery
-if ( count( $attachments ) > 1 ) {
- if ( isset( $attachments[ $k ] ) )
+if ( count( $attachments ) > 1 ) :
+ if ( isset( $attachments[ $k ] ) ) :
// get the URL of the next image attachment
$next_attachment_url = get_attachment_link( $attachments[ $k ]->ID );
- else
+ else :
// or get the URL of the first image attachment
$next_attachment_url = get_attachment_link( $attachments[ 0 ]->ID );
-} else {
+ endif;
+else :
// or, if there's only 1 image, get the URL of the image
$next_attachment_url = wp_get_attachment_url();
-}
+endif;
?>
<a href="<?php echo esc_url( $next_attachment_url ); ?>" title="<?php the_title_attribute(); ?>" rel="attachment"><?php
$attachment_size = apply_filters( 'twentytwelve_attachment_size', array( 960, 960 ) );
@@ -5,7 +5,8 @@
* This is the most generic template file in a WordPress theme
* and one of the two required files for a theme (the other being style.css).
* It is used to display a page when nothing more specific matches a query.
- * E.g., it puts together the home page when no home.php file exists.
+ * For example, it puts together the home page when no home.php file exists.
+ *
* Learn more: http://codex.wordpress.org/Template_Hierarchy
*
* @package WordPress
@@ -0,0 +1,52 @@
+<?php
+/**
+ * The template for displaying Tag pages.
+ *
+ * Used to display archive-type pages for posts in a tag.
+ *
+ * Learn more: http://codex.wordpress.org/Template_Hierarchy
+ *
+ * @package WordPress
+ * @subpackage Twenty_Twelve
+ * @since Twenty Twelve 1.0
+ */
+
+get_header(); ?>
+
+ <section id="primary" class="site-content">
+ <div id="content" role="main">
+
+ <?php if ( have_posts() ) : ?>
+ <header class="archive-header">
+ <h1 class="archive-title"><?php printf( __( 'Tag Archives: %s', 'twentytwelve' ), '<span>' . single_tag_title( '', false ) . '</span>' ); ?></h1>
+
+ <?php if ( tag_description() ) : // Show an optional tag description ?>
+ <div class="archive-meta"><?php echo tag_description(); ?></div>
+ <?php endif; ?>
+
+ </header><!-- .archive-header -->
+
+ <?php
+ /* Start the Loop */
+ while ( have_posts() ) : the_post();
+
+ /* Include the post format-specific template for the content. If you want to
+ * this in a child theme then include a file called called content-___.php
+ * (where ___ is the post format) and that will be used instead.
+ */
+ get_template_part( 'content', get_post_format() );
+
+ endwhile;
+
+ twentytwelve_content_nav( 'nav-below' );
+ ?>
+
+ <?php else : ?>
+ <?php get_template_part( 'content', 'none' ); ?>
+ <?php endif; ?>
+
+ </div><!-- #content -->
+ </section><!-- #primary -->
+
+<?php get_sidebar(); ?>
+<?php get_footer(); ?>

0 comments on commit 3d954a4

Please sign in to comment.