From 633e58960dbbf0cb46b2e8a957a61ee31bb9e003 Mon Sep 17 00:00:00 2001 From: Lance Willett Date: Wed, 14 Aug 2013 16:38:01 +0000 Subject: [PATCH] Twenty Fourteen: first pass at matching code standards achieved with Twenty Thirteen development. See #24858, props obenland. git-svn-id: https://develop.svn.wordpress.org/trunk@25021 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-content/themes/twentyfourteen/404.php | 30 ++- .../themes/twentyfourteen/archive.php | 92 +++------ .../themes/twentyfourteen/comments.php | 102 +++++---- .../twentyfourteen/content-featured-post.php | 52 ++--- .../themes/twentyfourteen/content-page.php | 17 +- .../twentyfourteen/content-post-format.php | 28 ++- .../content-recent-formatted-post.php | 58 +++--- .../themes/twentyfourteen/content-single.php | 56 ++--- .../themes/twentyfourteen/content.php | 60 +++--- .../twentyfourteen/featured-content.php | 3 +- .../themes/twentyfourteen/footer.php | 23 +-- .../themes/twentyfourteen/front-page.php | 51 +++++ .../themes/twentyfourteen/full-width-page.php | 64 ++---- .../themes/twentyfourteen/functions.php | 124 +++++++---- .../themes/twentyfourteen/header.php | 27 +-- .../themes/twentyfourteen/image.php | 80 +++----- .../twentyfourteen/inc/custom-header.php | 74 ++----- .../themes/twentyfourteen/inc/customizer.php | 2 +- .../twentyfourteen/inc/template-tags.php | 26 +-- .../themes/twentyfourteen/index.php | 77 ++----- .../themes/twentyfourteen/no-results.php | 34 ++- src/wp-content/themes/twentyfourteen/page.php | 65 ++---- .../themes/twentyfourteen/search.php | 36 ++-- .../themes/twentyfourteen/searchform.php | 12 +- .../themes/twentyfourteen/sidebar.php | 36 ++-- .../themes/twentyfourteen/single.php | 37 ++-- .../themes/twentyfourteen/style.css | 193 ++++++++++-------- 27 files changed, 646 insertions(+), 813 deletions(-) create mode 100644 src/wp-content/themes/twentyfourteen/front-page.php diff --git a/src/wp-content/themes/twentyfourteen/404.php b/src/wp-content/themes/twentyfourteen/404.php index 0de18a3c98..df1a51b0ca 100644 --- a/src/wp-content/themes/twentyfourteen/404.php +++ b/src/wp-content/themes/twentyfourteen/404.php @@ -11,24 +11,20 @@ get_header(); ?>
-
-
-

-
+ -
-

+
+

- + +
-
-
+
+
- - - - - - - - \ No newline at end of file +
- +
' ); - - } elseif ( is_tag() ) { - // show an optional tag description - $tag_description = tag_description(); - if ( ! empty( $tag_description ) ) - echo apply_filters( 'tag_archive_meta', '
' . $tag_description . '
' ); - } - ?> - + + twentyfourteen_get_template_part(); + endwhile; + twentyfourteen_content_nav( 'nav-below' ); - + else : + get_template_part( 'no-results', 'archive' ); - + endif; + ?> + +
- - - - - - - - - - - - - - \ No newline at end of file + - - -
- - +
-

- ' . get_the_title() . '' ); - ?> -

- 1 && get_option( 'page_comments' ) ) : // are there comments to navigate through ?> - - +

+ +

-
    - 'twentyfourteen_comment' ) ); - ?> -
+ 1 && get_option( 'page_comments' ) ) : ?> + + - 1 && get_option( 'page_comments' ) ) : // are there comments to navigate through ?> - - +
    + 'ol', + 'short_ping' => true, + + // TODO: Remove callback and update styles. + 'callback'=>'twentyfourteen_comment', + ) ); + ?> +
+ + 1 && get_option( 'page_comments' ) ) : ?> + + + + +

+ - -

- - -
+
diff --git a/src/wp-content/themes/twentyfourteen/content-featured-post.php b/src/wp-content/themes/twentyfourteen/content-featured-post.php index 63cd36a458..1c2a21af58 100644 --- a/src/wp-content/themes/twentyfourteen/content-featured-post.php +++ b/src/wp-content/themes/twentyfourteen/content-featured-post.php @@ -5,41 +5,47 @@ */ ?> -
> - +
> + $post->ID, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'orderby' => 'menu_order', 'order' => 'ASC', 'numberposts' => 1 ) ); - - if ( '' != get_the_post_thumbnail() ) : + if ( has_post_thumbnail() ) : the_post_thumbnail( 'featured-thumbnail-featured' ); - elseif ( $images ) : - $image = array_shift( $images ); - echo wp_get_attachment_image( $image->ID, 'featured-thumbnail-featured' ); - else : ?> - get_the_ID(), + 'post_type' => 'attachment', + 'post_mime_type' => 'image', + 'orderby' => 'menu_order', + 'order' => 'ASC', + 'numberposts' => 1, + ) ); + + if ( $images ) : + $image = array_shift( $images ); + echo wp_get_attachment_image( $image->ID, 'featured-thumbnail-featured' ); + + else : ?> +
+ -

+ + + ', '' ); ?>
-
+
- -
\ No newline at end of file +
diff --git a/src/wp-content/themes/twentyfourteen/content-page.php b/src/wp-content/themes/twentyfourteen/content-page.php index d5c7f0bc9e..4227eab845 100644 --- a/src/wp-content/themes/twentyfourteen/content-page.php +++ b/src/wp-content/themes/twentyfourteen/content-page.php @@ -1,6 +1,6 @@
> -
-

-
+

', '

' ); ?> -
- +
'', 'link_before' => '', - 'link_after' => '' + 'link_after' => '', ) ); + + edit_post_link( __( 'Edit', 'twentyfourteen' ), '', '' ); ?> - ', '' ); ?>
-
+ diff --git a/src/wp-content/themes/twentyfourteen/content-post-format.php b/src/wp-content/themes/twentyfourteen/content-post-format.php index 6c693ea7fe..b25487a215 100644 --- a/src/wp-content/themes/twentyfourteen/content-post-format.php +++ b/src/wp-content/themes/twentyfourteen/content-post-format.php @@ -43,41 +43,37 @@ $format = get_post_format(); - - + if ( ! post_password_required() && ( comments_open() || '0' != get_comments_number() ) ) : + ?> + ', '' ); ?> -
- →', 'twentyfourteen' ) ); ?> +
→', 'twentyfourteen' ) ); wp_link_pages( array( 'before' => '', 'link_before' => '', - 'link_after' => '' + 'link_after' => '', ) ); ?>
- + - - - + + +
- - \ No newline at end of file + diff --git a/src/wp-content/themes/twentyfourteen/content-recent-formatted-post.php b/src/wp-content/themes/twentyfourteen/content-recent-formatted-post.php index 48bb7db9d2..5a09da081b 100644 --- a/src/wp-content/themes/twentyfourteen/content-recent-formatted-post.php +++ b/src/wp-content/themes/twentyfourteen/content-recent-formatted-post.php @@ -6,29 +6,39 @@ if ( isset( $GLOBALS['content_width'] ) ) $GLOBALS['content_width'] = 306; -$format = get_post_format(); -if ( false === $format ) - $format = 'standard'; +$images = get_posts( array( + 'post_parent' => get_post()->post_parent, + 'fields' => 'ids', + 'numberposts' => -1, + 'post_status' => 'inherit', + 'post_type' => 'attachment', + 'post_mime_type' => 'image', + 'order' => 'ASC', + 'orderby' => 'menu_order ID' +) ); +$total_images = count( $images ); ?> -
> -
+
> +
$post->ID, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'orderby' => 'menu_order', 'order' => 'ASC' ) ); - if ( $images ) : - $total_images = count( $images ); - if ( empty( $featured_image ) ) { - $image = array_shift( $images ); - $featured_image = wp_get_attachment_image( $image->ID, 'featured-thumbnail-formatted' ); - } + if ( has_post_format( 'gallery' ) ) : + if ( has_post_thumbnail() ) : + $featured_image = get_the_post_thumbnail( get_the_ID(), 'featured-thumbnail-formatted' ); + elseif ( $total_images > 0 ) : + $image = array_shift( $images ); + $featured_image = wp_get_attachment_image( $image, 'featured-thumbnail-formatted' ); ?> - -

%2$s photo.', 'This gallery contains %2$s photos.', $total_images, 'twentyfourteen' ), - 'href="' . get_permalink() . '" title="' . esc_attr( sprintf( __( 'Permalink to %s', 'twentyfourteen' ), the_title_attribute( 'echo=0' ) ) ) . '" rel="bookmark"', + +

+ %2$s photo.', 'This gallery contains %2$s photos.', $total_images, 'twentyfourteen' ), + esc_url( get_permalink() ), number_format_i18n( $total_images ) - ); ?>

+

+ -
\ No newline at end of file +
diff --git a/src/wp-content/themes/twentyfourteen/content-single.php b/src/wp-content/themes/twentyfourteen/content-single.php index 6be2984c8f..073f9211ef 100644 --- a/src/wp-content/themes/twentyfourteen/content-single.php +++ b/src/wp-content/themes/twentyfourteen/content-single.php @@ -3,40 +3,31 @@ * @package WordPress * @subpackage Twenty_Fourteen */ -$format = get_post_format(); -if ( false === $format ) - $format = 'standard'; +has_post_format() ?>
> - +
+ + -

- + if ( ! has_post_format( array( 'status', 'chat', 'aside', 'link', 'quote', 'audio' ) ) ) : + the_title( '

', '

' ); + endif; + ?>
-
- +
'', 'link_before' => '', - 'link_after' => '' + 'link_after' => '', ) ); ?>
- + - + - + - +
-
+ diff --git a/src/wp-content/themes/twentyfourteen/content.php b/src/wp-content/themes/twentyfourteen/content.php index 02e214bfd9..62e1a9ea01 100644 --- a/src/wp-content/themes/twentyfourteen/content.php +++ b/src/wp-content/themes/twentyfourteen/content.php @@ -3,74 +3,66 @@ * @package WordPress * @subpackage Twenty_Fourteen */ -$format = get_post_format(); + ?> -
> +
> - +
- +

-
+
-
- →', 'twentyfourteen' ) ); ?> +
→', 'twentyfourteen' ) ); wp_link_pages( array( 'before' => '', 'link_before' => '', - 'link_after' => '' + 'link_after' => '', ) ); ?>
- -
- -
- -
\ No newline at end of file + +
+ +
+ +
diff --git a/src/wp-content/themes/twentyfourteen/featured-content.php b/src/wp-content/themes/twentyfourteen/featured-content.php index 79bb599f40..726f21c7c5 100644 --- a/src/wp-content/themes/twentyfourteen/featured-content.php +++ b/src/wp-content/themes/twentyfourteen/featured-content.php @@ -1,5 +1,5 @@ - - +
+
+ + +
+
+
+ \ No newline at end of file diff --git a/src/wp-content/themes/twentyfourteen/front-page.php b/src/wp-content/themes/twentyfourteen/front-page.php new file mode 100644 index 0000000000..56a4b66061 --- /dev/null +++ b/src/wp-content/themes/twentyfourteen/front-page.php @@ -0,0 +1,51 @@ + + +
+
+ + + + + +
+ +
+
+ +
+
+ + + +
+ +
+
+ + - - -
-
- - - - - -
- -
-
- -
-
- -
- -
-
- - -
+ + get_template_part( 'content', 'page' ); - + // If comments are open or we have at least one comment, load up the comment template. + if ( comments_open() || get_comments_number() ) + comments_template(); + endwhile; + ?> +
+
- - - - - - - - - - - - + 'f5f5f5' ) ); - - if ( function_exists( 'wp_get_theme' ) ) { - add_theme_support( 'custom-background', $args ); - } else { - // Compat: Versions of WordPress prior to 3.4. - define( 'BACKGROUND_COLOR', $args['default-color'] ); - add_custom_background(); - } + add_theme_support( 'custom-background', apply_filters( 'twentyfourteen_custom_background_args', array( + 'default-color' => 'f5f5f5', + ) ) ); } endif; // twentyfourteen_setup add_action( 'after_setup_theme', 'twentyfourteen_setup' ); @@ -112,16 +96,9 @@ function twentyfourteen_has_featured_posts( $minimum = 1 ) { if ( is_paged() ) return false; - $minimum = absint( $minimum ); $featured_posts = apply_filters( 'twentyfourteen_get_featured_posts', array() ); - if ( ! is_array( $featured_posts ) ) - return false; - - if ( $minimum > count( $featured_posts ) ) - return false; - - return true; + return is_array( $featured_posts ) && count( $featured_posts ) > absint( $minimum ); } /** @@ -191,18 +168,14 @@ function twentyfourteen_widgets_init() { add_action( 'widgets_init', 'twentyfourteen_widgets_init' ); /** - * Register Google fonts for Twenty Fourteen + * Register Google fonts for Twenty Fourteen. * */ function twentyfourteen_fonts() { /* translators: If there are characters in your language that are not supported by Lato, translate this to 'off'. Do not translate into your own language. */ - if ( 'off' !== _x( 'on', 'Lato font: on or off', 'twentyfourteen' ) ) { - - $protocol = is_ssl() ? 'https' : 'http'; - - wp_register_style( 'twentyfourteen-lato', "$protocol://fonts.googleapis.com/css?family=Lato:100,300,400,700,900,100italic,300italic,400italic,700italic,900italic", array(), null ); - } + if ( 'off' !== _x( 'on', 'Lato font: on or off', 'twentyfourteen' ) ) + wp_register_style( 'twentyfourteen-lato', '//fonts.googleapis.com/css?family=Lato:100,300,400,700,900,100italic,300italic,400italic,700italic,900italic', array(), null ); } add_action( 'init', 'twentyfourteen_fonts' ); @@ -215,13 +188,11 @@ function twentyfourteen_scripts() { wp_enqueue_style( 'twentyfourteen-lato' ); - if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) { + if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) wp_enqueue_script( 'comment-reply' ); - } - if ( is_singular() && wp_attachment_is_image() ) { + if ( is_singular() && wp_attachment_is_image() ) wp_enqueue_script( 'twentyfourteen-keyboard-image-navigation', get_template_directory_uri() . '/js/keyboard-image-navigation.js', array( 'jquery' ), '20130402' ); - } wp_enqueue_script( 'twentyfourteen-theme', get_template_directory_uri() . '/js/theme.js', array( 'jquery' ), '20130402', true ); } @@ -231,13 +202,10 @@ add_action( 'wp_enqueue_scripts', 'twentyfourteen_scripts' ); * Enqueue Google fonts style to admin screen for custom header display. * */ -function twentyfourteen_admin_fonts( $hook_suffix ) { - if ( 'appearance_page_custom-header' != $hook_suffix ) - return; - +function twentyfourteen_admin_fonts() { wp_enqueue_style( 'twentyfourteen-lato' ); } -add_action( 'admin_enqueue_scripts', 'twentyfourteen_admin_fonts' ); +add_action( 'admin_print_scripts-appearance_page_custom-header', 'twentyfourteen_admin_fonts' ); /** * Implement the Custom Header feature @@ -285,6 +253,62 @@ function twentyfourteen_custom_excerpt_more( $output ) { } add_filter( 'get_the_excerpt', 'twentyfourteen_custom_excerpt_more' ); +if ( ! function_exists( 'twentyfourteen_the_attached_image' ) ) : +/** + * Prints the attached image with a link to the next attached image. + * + * @since Twenty Thirteen 1.0 + * + * @return void + */ +function twentyfourteen_the_attached_image() { + $post = get_post(); + $attachment_size = apply_filters( 'twentyfourteen_attachment_size', array( 1200, 1200 ) ); + $next_attachment_url = wp_get_attachment_url(); + + /** + * Grab the IDs of all the image attachments in a gallery so we can get the URL + * of the next adjacent image in a gallery, 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. + */ + $attachment_ids = get_posts( array( + 'post_parent' => $post->post_parent, + 'fields' => 'ids', + 'numberposts' => -1, + '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( $attachment_ids ) > 1 ) { + foreach ( $attachment_ids as $attachment_id ) { + if ( $attachment_id == $post->ID ) { + $next_id = current( $attachment_ids ); + break; + } + } + + // get the URL of the next image attachment... + if ( $next_id ) + $next_attachment_url = get_attachment_link( $next_id ); + + // or get the URL of the first image attachment. + else + $next_attachment_url = get_attachment_link( array_shift( $attachment_ids ) ); + } + + printf( '%3$s', + esc_url( $next_attachment_url ), + the_title_attribute( array( 'echo' => false ) ), + wp_get_attachment_image( $post->ID, $attachment_size ) + ); +} +endif; + /** * Count the number of footer sidebars to enable dynamic classes for the footer * @@ -328,7 +352,7 @@ function twentyfourteen_footer_sidebar_class() { } if ( $class ) - echo 'class="clearfix ' . $class . '"'; + printf( 'class="%s"', $class ); } /** @@ -443,4 +467,14 @@ function twentyfourteen_wp_title( $title, $sep ) { return $title; } -add_filter( 'wp_title', 'twentyfourteen_wp_title', 10, 2 ); \ No newline at end of file +add_filter( 'wp_title', 'twentyfourteen_wp_title', 10, 2 ); + +/** + * Custom template tags for this theme. + */ +require get_template_directory() . '/inc/template-tags.php'; + +/** + * Customizer additions + */ +require get_template_directory() . '/inc/customizer.php'; diff --git a/src/wp-content/themes/twentyfourteen/header.php b/src/wp-content/themes/twentyfourteen/header.php index 1d11f89c50..8da029a882 100644 --- a/src/wp-content/themes/twentyfourteen/header.php +++ b/src/wp-content/themes/twentyfourteen/header.php @@ -10,13 +10,6 @@ ?> class="no-js"> - <?php wp_title( '|', true, 'right' ); ?> @@ -59,16 +52,16 @@ document.documentElement.className = document.documentElement.className.replace( + if ( ! empty( $header_image ) ) : ?> - + - -
\ No newline at end of file +
diff --git a/src/wp-content/themes/twentyfourteen/image.php b/src/wp-content/themes/twentyfourteen/image.php index 6cce17832e..89394cc398 100644 --- a/src/wp-content/themes/twentyfourteen/image.php +++ b/src/wp-content/themes/twentyfourteen/image.php @@ -9,14 +9,14 @@ 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(); - } - ?> - - ID, $attachment_size ); - ?> +
- post_excerpt ) ) : ?> +
- '', 'link_before' => '', - 'link_after' => '' + 'link_after' => '', ) ); ?>
- - Post a comment or leave a trackback: Trackback URL.', 'twentyfourteen' ), get_trackback_url() ); ?> - - Trackback URL.', 'twentyfourteen' ), get_trackback_url() ); ?> - - post a comment.', 'twentyfourteen' ); ?> - - - + Post a comment or leave a trackback: Trackback URL.', 'twentyfourteen' ), get_trackback_url() ); + elseif ( ! comments_open() && pings_open() ) : // Only trackbacks open + printf( __( 'Comments are closed, but you can leave a trackback: Trackback URL.', 'twentyfourteen' ), get_trackback_url() ); + elseif ( comments_open() && ! pings_open() ) : // Only comments open + _e( 'Trackbacks are closed, but you can post a comment.', 'twentyfourteen' ); + elseif ( ! comments_open() && ! pings_open() ) : // Comments and trackbacks closed + _e( 'Both comments and trackbacks are currently closed.', 'twentyfourteen' ); + endif; + ?>
-
+
', 'twentyfourteen' ) ); ?> @@ -112,9 +78,9 @@ get_header(); -
-
+
+ - - - \ No newline at end of file + '', + add_theme_support( 'custom-header', apply_filters( 'twentyfourteen_custom_header_args', array( 'default-text-color' => 'fff', 'width' => 1260, 'height' => 240, @@ -31,49 +30,11 @@ function twentyfourteen_custom_header_setup() { 'wp-head-callback' => 'twentyfourteen_header_style', 'admin-head-callback' => 'twentyfourteen_admin_header_style', 'admin-preview-callback' => 'twentyfourteen_admin_header_image', - ); + ) ) ); - $args = apply_filters( 'twentyfourteen_custom_header_args', $args ); - - if ( function_exists( 'wp_get_theme' ) ) { - add_theme_support( 'custom-header', $args ); - } else { - // Compat: Versions of WordPress prior to 3.4. - define( 'HEADER_TEXTCOLOR', $args['default-text-color'] ); - define( 'HEADER_IMAGE', $args['default-image'] ); - define( 'HEADER_IMAGE_WIDTH', $args['width'] ); - define( 'HEADER_IMAGE_HEIGHT', $args['height'] ); - add_custom_image_header( $args['wp-head-callback'], $args['admin-head-callback'], $args['admin-preview-callback'] ); - } } add_action( 'after_setup_theme', 'twentyfourteen_custom_header_setup' ); -/** - * Shiv for get_custom_header(). - * - * get_custom_header() was introduced to WordPress - * in version 3.4. To provide backward compatibility - * with previous versions, we will define our own version - * of this function. - * - * @todo Remove this function when WordPress 3.6 is released. - * @return stdClass All properties represent attributes of the curent header image. - * - * @package WordPress - * @subpackage Twenty_Fourteen - */ - -if ( ! function_exists( 'get_custom_header' ) ) { - function get_custom_header() { - return (object) array( - 'url' => get_header_image(), - 'thumbnail_url' => get_header_image(), - 'width' => HEADER_IMAGE_WIDTH, - 'height' => HEADER_IMAGE_HEIGHT, - ); - } -} - if ( ! function_exists( 'twentyfourteen_header_style' ) ) : /** * Styles the header image and text displayed on the blog @@ -82,17 +43,18 @@ if ( ! function_exists( 'twentyfourteen_header_style' ) ) : * */ function twentyfourteen_header_style() { + $header_text_color = get_header_textcolor(); // If no custom options for text are set, let's bail - // get_header_textcolor() options: HEADER_TEXTCOLOR is default, hide text (returns 'blank') or any hex value - if ( HEADER_TEXTCOLOR == get_header_textcolor() ) + // $header_text_color options: HEADER_TEXTCOLOR is default, hide text (returns 'blank') or any hex value + if ( HEADER_TEXTCOLOR == $header_text_color ) return; // If we get this far, we have custom styles. Let's do this. ?> @@ -153,19 +115,15 @@ if ( ! function_exists( 'twentyfourteen_admin_header_image' ) ) : * @see twentyfourteen_custom_header_setup(). * */ -function twentyfourteen_admin_header_image() { ?> +function twentyfourteen_admin_header_image() { + $header_image = get_header_image(); +?>
- - - + + -

onclick="return false;" href="">

+

onclick="return false;" href="">

-