From 6c83cfb5cceb79257d3db03ecd0d473939117b39 Mon Sep 17 00:00:00 2001 From: obenland Date: Tue, 4 Jun 2013 13:13:15 -0700 Subject: [PATCH] _s: Simplify image.php: * Extracts logic in a custom template tag. * Reduces switching in and out of php in `.entry-meta`. * Minor code styling changes. Fixes #233. --- image.php | 71 ++++++++++++------------------------------- inc/template-tags.php | 52 ++++++++++++++++++++++++++++++- 2 files changed, 70 insertions(+), 53 deletions(-) diff --git a/image.php b/image.php index 4151a7b0..0ac4d012 100644 --- a/image.php +++ b/image.php @@ -15,7 +15,7 @@ get_header();
>
-

+ ', '' ); ?>
-
- $post->post_parent, - 'post_status' => 'inherit', - 'post_type' => 'attachment', - 'post_mime_type' => 'image', - 'order' => 'ASC', - 'orderby' => 'menu_order ID' - ) ) ); - foreach ( $attachments as $k => $attachment ) { - if ( $attachment->ID == $post->ID ) - break; - } - $k++; - // If there is more than 1 attachment in a gallery - 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 - // or get the URL of the first image attachment - $next_attachment_url = get_attachment_link( $attachments[ 0 ]->ID ); - } else { - // or, if there's only 1 image, get the URL of the image - $next_attachment_url = wp_get_attachment_url(); - } - ?> - - +
@@ -89,29 +54,31 @@ get_header();
- '', ) ); ?> -
- - Post a comment or leave a trackback: Trackback URL.', '_s' ), get_trackback_url() ); ?> - - Trackback URL.', '_s' ), get_trackback_url() ); ?> - - post a comment.', '_s' ); ?> - - - - ', '' ); ?> + Post a comment or leave a trackback: Trackback URL.', '_s' ), get_trackback_url() ); + elseif ( ! comments_open() && pings_open() ) : // Only trackbacks open + printf( __( 'Comments are closed, but you can leave a trackback: Trackback URL.', '_s' ), get_trackback_url() ); + elseif ( comments_open() && ! pings_open() ) : // Only comments open + _e( 'Trackbacks are closed, but you can post a comment.', '_s' ); + elseif ( ! comments_open() && ! pings_open() ) : // Comments and trackbacks closed + _e( 'Both comments and trackbacks are currently closed.', '_s' ); + endif; + + edit_post_link( __( 'Edit', '_s' ), ' ', '' ); + ?>
-
+ $post->post_parent, + 'post_status' => 'inherit', + 'post_type' => 'attachment', + 'post_mime_type' => 'image', + 'order' => 'ASC', + 'orderby' => 'menu_order ID' + ) ) ); + + // If there is more than 1 attachment in a gallery... + if ( count( $attachments ) > 1 ) { + foreach ( $attachments as $k => $attachment ) { + if ( $attachment->ID == $post->ID ) + break; + } + $k++; + + // get the URL of the next image attachment... + if ( isset( $attachments[ $k ] ) ) + $next_attachment_url = get_attachment_link( $attachments[ $k ]->ID ); + + // or get the URL of the first image attachment. + else + $next_attachment_url = get_attachment_link( $attachments[0]->ID ); + } + + printf( '%3$s', + esc_url( $next_attachment_url ), + the_title_attribute( array( 'echo' => false ) ), + wp_get_attachment_image( $post->ID, $attachment_size ) + ); +} +endif; + if ( ! function_exists( '_s_posted_on' ) ) : /** * Prints HTML with meta information for the current post-date/time and author. @@ -125,6 +174,7 @@ function _s_posted_on() { ); } endif; + /** * Returns true if a blog has more than 1 category */ @@ -158,4 +208,4 @@ function _s_category_transient_flusher() { delete_transient( 'all_the_cool_cats' ); } add_action( 'edit_category', '_s_category_transient_flusher' ); -add_action( 'save_post', '_s_category_transient_flusher' ); \ No newline at end of file +add_action( 'save_post', '_s_category_transient_flusher' );