Permalink
Browse files

Improve attachment pages

- New file: loop-attachment.php - the loop for all non-image attachments
- New file: image.php - template for all image attachments
- New function: cakifo_get_image_size_links() - Returns a set of image
attachment links based on size
- CSS improved and LESS'd
-
  • Loading branch information...
jayj committed Oct 13, 2012
1 parent df772e8 commit 4837f8f4ecd23968568be438cba3453aec515c44
Showing with 252 additions and 153 deletions.
  1. +5 −76 attachment.php
  2. +37 −1 functions.php
  3. +78 −0 image.php
  4. +81 −0 loop-attachment.php
  5. +24 −31 style.dev.css
  6. +27 −45 style.dev.less
View
@@ -7,6 +7,7 @@
*
* @package Cakifo
* @subpackage Template
+ * @since Cakifo 1.0
*/
get_header(); // Loads the header.php template ?>
@@ -17,85 +18,13 @@
<?php do_atomic( 'open_main' ); // cakifo_open_main ?>
- <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
+ <?php get_template_part( 'loop-meta' ); // Loads the loop-meta.php template ?>
- <?php do_atomic( 'before_entry' ); //cakifo_before_entry ?>
+ <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
- <article id="post-<?php the_ID(); ?>" class="<?php hybrid_entry_class(); ?>">
+ <?php get_template_part( 'loop', 'attachment' ); ?>
- <?php do_atomic( 'open_entry' ); //cakifo_open_entry ?>
-
- <header class="entry-header">
- <?php
- echo apply_atomic_shortcode( "attachment_metadeta", '<div class="entry-format">' . sprintf(
- __( 'Published on [entry-published] in <a href="%1$s" title="Return to %2$s" rel="gallery">%2$s</a> [entry-edit-link before=" | "]', 'cakifo' ),
- esc_url( get_permalink( $post->post_parent ) ),
- get_the_title( $post->post_parent )
- ) . '</div>' );
- ?>
- <?php echo apply_atomic_shortcode( 'entry_title', '[entry-title]' ); ?>
- </header> <!-- .entry-header -->
-
- <div class="entry-content">
- <?php
- /* Image attachments */
- if ( wp_attachment_is_image( get_the_ID() ) ) :
- ?>
- <p class="attachment-image">
- <a href="<?php echo wp_get_attachment_url( get_the_ID() ); ?>" title="<?php esc_attr_e( 'View full size', 'cakifo' ); ?>">
- <?php echo wp_get_attachment_image( get_the_ID(), 'full', false, array( 'class' => 'aligncenter' ) ); ?>
- </a>
- </p> <!-- .attachment-image -->
-
- <?php if ( has_excerpt() ) : ?>
- <div class="entry-caption">
- <?php the_excerpt(); ?>
- </div>
- <?php endif; ?>
- <?php else : ?>
-
- <?php hybrid_attachment(); // Function for handling non-image attachments ?>
-
- <p class="download">
- <a href="<?php echo wp_get_attachment_url(); ?>" title="<?php the_title_attribute(); ?>" rel="enclosure" type="<?php echo get_post_mime_type(); ?>"><?php printf( __( 'Download %s', 'cakifo' ), the_title( '<span class="fn">&quot;', '&quot;</span>', false) ); ?></a>
- </p> <!-- .download -->
-
- <?php endif; ?>
-
- <?php the_content(); ?>
- <?php wp_link_pages( array( 'before' => '<p class="page-links">' . __( 'Pages:', 'cakifo' ), 'after' => '</p>' ) ); ?>
- </div> <!-- .entry-content -->
-
- <?php if ( wp_attachment_is_image( get_the_ID() ) ) : ?>
-
- <aside id="image-info">
- <?php cakifo_image_info(); // Get image meta data ?>
-
- <?php $gallery = do_shortcode( sprintf( '[gallery id="%1$s" exclude="%2$s" columns="5" size="small" numberposts="20" orderby="rand"]', $post->post_parent, get_the_ID() ) ); ?>
-
- <?php if ( ! empty( $gallery ) ) { ?>
- <div id="attachment-gallery">
- <h4><?php _e( 'Gallery', 'cakifo' ); ?></h4>
- <?php echo $gallery; ?>
- </div> <!-- #attachment-gallery -->
- <?php } ?>
- </aside> <!-- #image-info -->
-
- <?php endif; ?>
-
- <div class="clear"></div>
-
- <?php do_atomic( 'close_entry' ); //cakifo_close_entry ?>
-
- </article> <!-- #post-<?php the_ID(); ?> -->
-
- <?php get_sidebar( 'after-singular' ); // Loads the sidebar-after-singular.php template ?>
-
- <?php do_atomic( 'after_singular' ); // cakifo_after_singular ?>
-
- <?php comments_template( '/comments.php', true ); // Loads the comments.php template ?>
-
- <?php endwhile; ?>
+ <?php endwhile; ?>
<?php do_atomic( 'close_main' ); // cakifo_close_main ?>
View
@@ -818,7 +818,7 @@ function cakifo_image_info() {
/* Format the HTML output of the function */
$output = '<div class="image-info">
- <h4>' . __( 'Image Info', 'cakifo' ) . '</h4>
+ <h3>' . __( 'Image Info', 'cakifo' ) . '</h3>
<dl>' . $list . '</dl>
</div> <!-- .image-info -->';
@@ -874,6 +874,42 @@ function cakifo_get_image_size( $name ) {
return false;
}
+/**
+ * Returns a set of image attachment links based on size.
+ *
+ * @author Justin Tadlock
+ * @link http://justintadlock.com
+ * @return string Links to various image sizes for the image attachment.
+ * @since Cakifo 1.5
+ */
+function cakifo_get_image_size_links() {
+
+ /* If not viewing an image attachment page, return. */
+ if ( ! wp_attachment_is_image( get_the_ID() ) )
+ return;
+
+ /* Set up an empty array for the links. */
+ $links = array();
+
+ /* Get the intermediate image sizes and add the full size to the array. */
+ $sizes = get_intermediate_image_sizes();
+ $sizes[] = 'full';
+
+ /* Loop through each of the image sizes. */
+ foreach ( $sizes as $size ) {
+
+ /* Get the image source, width, height, and whether it's intermediate. */
+ $image = wp_get_attachment_image_src( get_the_ID(), $size );
+
+ /* Add the link to the array if there's an image and if $is_intermediate (4th array value) is true or full size. */
+ if ( !empty( $image ) && ( true === $image[3] || 'full' == $size ) )
+ $links[] = "<a class='image-size-link' href='" . esc_url( $image[0] ) . "'>{$image[1]} &times; {$image[2]}</a>";
+ }
+
+ /* Join the links in a string and return. */
+ return join( ' <span class="sep">/</span> ', $links );
+}
+
/**
* @since Cakifo 1.0
* @deprecated Cakifo 1.3 Use the native WordPress function wp_trim_words() instead.
View
@@ -0,0 +1,78 @@
+<?php
+/**
+ * Attachment Template
+ *
+ * This is the image attachment template. It is used when visiting the singular view of an image attachment
+ * page.
+ *
+ * @package Cakifo
+ * @subpackage Template
+ * @since Cakifo 1.5
+ */
+
+get_header(); // Loads the header.php template ?>
+
+ <?php do_atomic( 'before_main' ); // cakifo_before_main ?>
+
+ <div id="main">
+
+ <?php do_atomic( 'open_main' ); // cakifo_open_main ?>
+
+ <?php get_template_part( 'loop-meta' ); // Loads the loop-meta.php template ?>
+
+ <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
+
+ <?php do_atomic( 'before_entry' ); //cakifo_before_entry ?>
+
+ <article id="post-<?php the_ID(); ?>" class="<?php hybrid_entry_class(); ?>">
+
+ <?php do_atomic( 'open_entry' ); //cakifo_open_entry ?>
+
+ <header class="entry-header">
+ <?php echo apply_atomic_shortcode( 'entry_title', '[entry-title permalink=""]' ); ?>
+ <?php echo apply_atomic_shortcode( 'byline_attachment_image', '<div class="byline">' . sprintf( __( 'Sizes: %s', 'cakifo' ), cakifo_get_image_size_links() ) . '</div>' ); ?>
+ </header> <!-- .entry-header -->
+
+ <div class="entry-content">
+ <?php
+ if ( has_excerpt() ) {
+ $src = wp_get_attachment_image_src( get_the_ID(), 'full' );
+ echo do_shortcode( sprintf( '[caption align="aligncenter" width="%1$s"]%3$s %2$s[/caption]', esc_attr( $src[1] ), get_the_excerpt(), wp_get_attachment_image( get_the_ID(), 'full', false ) ) );
+ } else {
+ echo wp_get_attachment_image( get_the_ID(), 'full', false, array( 'class' => 'aligncenter' ) );
+ }
+ ?>
+
+ <?php the_content(); ?>
+ <?php wp_link_pages( array( 'before' => '<p class="page-links">' . __( 'Pages:', 'unique' ), 'after' => '</p>' ) ); ?>
+ </div> <!-- .entry-content -->
+
+ <aside class="attachment-meta clearfix">
+ <?php cakifo_image_info(); // Get image meta data ?>
+
+ <?php $gallery = do_shortcode( sprintf( '[gallery id="%1$s" exclude="%2$s" columns="5" size="small" numberposts="20" orderby="rand"]', $post->post_parent, get_the_ID() ) ); ?>
+
+ <?php if ( ! empty( $gallery ) ) { ?>
+ <div class="image-gallery">
+ <h3><?php _e( 'Gallery', 'cakifo' ); ?></h3>
+ <?php echo $gallery; ?>
+ </div> <!-- .image-gallery -->
+ <?php } ?>
+ </aside> <!-- .attachment-meta -->
+
+ <?php do_atomic( 'in_singular' ); // cakifo_in_singular (+ cakifo_after_singular) ?>
+
+ <?php do_atomic( 'close_entry' ); //cakifo_close_entry ?>
+ </article> <!-- #post-<?php the_ID(); ?> -->
+
+ <?php endwhile; ?>
+
+ <?php do_atomic( 'close_main' ); // cakifo_close_main ?>
+
+ <?php get_template_part( 'loop-nav' ); // Loads the loop-nav.php template ?>
+
+ </div> <!-- #main -->
+
+ <?php do_atomic( 'after_main' ); // cakifo_after_main ?>
+
+<?php get_footer(); // Loads the footer.php template ?>
View
@@ -0,0 +1,81 @@
+<?php
+/**
+ * Attachment Content Template
+ *
+ * Template used to show the post content of the attachment post type.
+ *
+ * This can be overridden in child themes with loop-attachment.php
+ *
+ * @package Cakifo
+ * @subpackage Template
+ * @since Cakifo 1.5
+ */
+
+do_atomic( 'before_entry' ); //cakifo_before_entry ?>
+
+<article id="post-<?php the_ID(); ?>" class="<?php hybrid_entry_class(); ?>">
+
+ <?php do_atomic( 'open_entry' ); //cakifo_open_entry ?>
+
+ <?php if ( is_singular() && is_main_query() ) : ?>
+
+ <header class="entry-header">
+ <?php echo apply_atomic_shortcode( 'entry_title', '[entry-title permalink=""]' ); ?>
+ </header> <!-- .entry-header -->
+
+ <?php
+ /**
+ * Get the thumbnail
+ */
+ if ( current_theme_supports( 'get-the-image' ) )
+ get_the_image( array(
+ 'size' => 'thumbnail',
+ 'attachment' => false
+ ) );
+ ?>
+
+ <div class="entry-content">
+ <?php hybrid_attachment(); // Function for handling non-image attachments. ?>
+
+ <p class="download">
+ <a href="<?php echo wp_get_attachment_url(); ?>" title="<?php the_title_attribute(); ?>" type="<?php echo get_post_mime_type(); ?>">
+ <?php printf( __( 'Download %s', 'cakifo' ), the_title( '<span class="fn">&quot;', '&quot;</span>', false) ); ?>
+ </a>
+ </p> <!-- .download -->
+
+ <?php the_content(); ?>
+ <?php wp_link_pages( array( 'before' => '<p class="page-links">' . __( 'Pages:', 'cakifo' ), 'after' => '</p>' ) ); ?>
+ </div> <!-- .entry-content -->
+
+ <?php echo apply_atomic_shortcode( 'entry_meta_attachment', '<footer class="entry-meta">' . __( 'Published on [entry-published] [entry-edit-link before="| "]', 'cakifo' ) . '</footer> <!-- .entry-meta -->' ); ?>
+
+ <?php do_atomic( 'in_singular' ); // cakifo_in_singular (+ cakifo_after_singular) ?>
+
+ <?php else : ?>
+
+ <header class="entry-header">
+ <?php echo apply_atomic_shortcode( 'entry_title', '[entry-title]' ); ?>
+ </header> <!-- .entry-header -->
+
+ <?php
+ /**
+ * Get the thumbnail
+ */
+ if ( current_theme_supports( 'get-the-image' ) )
+ get_the_image( array(
+ 'size' => 'thumbnail',
+ 'attachment' => false
+ ) );
+ ?>
+
+ <div class="entry-summary">
+ <?php the_excerpt(); ?>
+ <?php wp_link_pages( array( 'before' => '<p class="page-links">' . __( 'Pages:', 'cakifo' ), 'after' => '</p>' ) ); ?>
+ </div> <!-- .entry-summary -->
+
+ <?php endif; ?>
+
+ <?php do_atomic( 'close_entry' ); //cakifo_close_entry ?>
+</article> <!-- #post-<?php the_ID(); ?> -->
+
+<?php do_atomic( 'after_entry' ); //cakifo_after_entry ?>
View
@@ -1771,51 +1771,44 @@ table caption {
/* =============================================================================
Components: Attachment pages
========================================================================== */
-#image-info {
- overflow: hidden;
-}
-#image-info h4 {
- margin-bottom: 20px;
-}
-#image-info .image-info {
- width: 286px;
+.image-info {
float: left;
- margin: 0 40px 0 0;
-}
-.image-info dl,
-.image-info dt,
-.image-info dd {
- margin: 0;
+ width: 35%;
}
.image-info dl {
- line-height: 50px;
+ line-height: 40px;
}
.image-info dt {
- border-bottom: 1px solid #dfdfdf;
+ border-bottom: 1px solid #eeeeee;
font-size: 16px;
- float: left;
- width: 100%;
- padding: 5px 10px;
text-align: left;
clear: left;
+ float: left;
+ width: 100%;
+ padding: 5px;
+}
+.image-info dt:hover,
+.image-info dt:active {
+ background-color: #f2f7fc;
+ background-image: -moz-linear-gradient(left, #f7fafc 40%, #f2f7fc);
+ background-image: -webkit-linear-gradient(left, #f7fafc 40%, #f2f7fc);
+ background-image: -o-linear-gradient(left, #f7fafc 40%, #f2f7fc);
+ background-image: linear-gradient(left, #f7fafc 40%, #f2f7fc);
+ background-repeat: repeat-x;
}
.image-info dd {
- font: 14px 'PT Serif', Georgia, serif;
+ font-family: 'PT Serif', Georgia, Cambria, "Bitstream Charter", serif;
+ font-size: 14px;
+ font-weight: normal;
+ line-height: 1.8;
float: right;
- margin-top: -40px;
+ margin-top: -38px;
+ padding-right: 5px;
text-align: right;
}
-.image-info dt:hover {
- background: #f7fafc;
- background-image: -webkit-linear-gradient(left, #f7fafc 50%, #f2f7fc);
- background-image: -moz-linear-gradient(left, #f7fafc 50%, #f2f7fc);
- background-image: -o-linear-gradient(left, #f7fafc 50%, #f2f7fc);
- background-image: -ms-linear-gradient(left, #f7fafc 50%, #f2f7fc);
- background-image: linear-gradient(to left, #f7fafc 50%, #f2f7fc);
-}
-#attachment-gallery {
- width: 600px;
+.image-gallery {
float: right;
+ width: 60%;
}
/* =============================================================================
Layout: 404 Error Page
Oops, something went wrong.

0 comments on commit 4837f8f

Please sign in to comment.