Permalink
Browse files

Add option to display featured post images in the header.

Thanks to Martin Lormes for suggesting this change and writing the
initial implementation, which was inspired by a feature in the
default WordPress theme Twenty Eleven.
  • Loading branch information...
1 parent 954469c commit 5c47e24833ee014e69c3d091c0e65b6b74e65a99 @beastaugh committed Apr 22, 2012
Showing with 34 additions and 20 deletions.
  1. +1 −0 changelog.txt
  2. +12 −4 functions.php
  3. +1 −1 library/helpers/admin_helper.php
  4. +20 −15 library/helpers/template_helper.php
View
@@ -2,6 +2,7 @@
### Version 3.2.0
+ * Added option to display featured post images in the header.
* Moved language files to `/languages` directory.
* Added POT file to theme files in `languages` directory.
* Replaced use of deprecated `add_custom_image_header` function.
View
@@ -156,10 +156,18 @@
// Post thumbnails; change these settings via a child theme or plugin
add_theme_support('post-thumbnails');
-if (get_tarski_option('featured_header'))
-set_post_thumbnail_size(HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT, true);
-else
-set_post_thumbnail_size(150, 150, false);
+
+if (get_tarski_option('featured_header')) {
+ set_post_thumbnail_size(HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT, true);
+} else {
+ set_post_thumbnail_size($content_width, 300, false);
+}
+
+// Image size for large feature images, used in the header
+add_image_size('large-feature', HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT, true);
+
+// Image size for featured posts if a large-feature doesn't exist
+add_image_size('small-feature', $content_width, 300);
// Post types
add_theme_support('post-formats', array('aside'));
@@ -317,7 +317,7 @@ function tarski_miscellaneous_options() {
'centred_theme' => __('Centrally align the theme', 'tarski'),
'swap_sides' => __('Switch column order', 'tarski'),
'swap_title_order' => __('Reverse document title order', 'tarski'),
- 'featured_header' => __('Featured images in header', 'tarski'));
+ 'featured_header' => __('Display featured images in header', 'tarski'));
foreach ($checkboxes as $name => $label)
$output .= tarski_option_checkbox($name, $label) . "\n\n";
@@ -277,32 +277,37 @@ function _tarski_asset_output($type, $assets) {
* @uses user_trailingslashit
* @uses home_url
*
+ * @global object $post
+ *
* @return string
*/
function tarski_headerimage() {
global $post;
+
if (!get_theme_mod('header_image')) return;
$header_img_url = get_header_image();
- // inspired by twentyeleven
- if ( get_tarski_option('featured_header') &&
- is_singular() &&
- has_post_thumbnail( $post->ID ) &&
- ( /* $src, $width, $height */ $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), array( HEADER_IMAGE_WIDTH, HEADER_IMAGE_WIDTH ) ) ) &&
- $image[1] >= HEADER_IMAGE_WIDTH )
- // Houston, we have a new header image!
- $header_img_tag = get_the_post_thumbnail( $post->ID, 'post-thumbnail' );
- else {
+ if (get_tarski_option('featured_header') &&
+ is_singular($post) &&
+ has_post_thumbnail($post->ID)) {
+ $image_size = array(HEADER_IMAGE_WIDTH, HEADER_IMAGE_WIDTH);
+ $image_id = get_post_thumbnail_id($post->ID);
+ $image = wp_get_attachment_image_src($image_id, $image_size);
+
+ if ($image[1] >= HEADER_IMAGE_WIDTH) {
+ $header_img_tag = get_the_post_thumbnail($post->ID, $image_size);
+ }
+ }
if (!$header_img_url) return;
- $header_img_tag = sprintf('<img alt="%s" src="%s">',
- get_tarski_option('display_title')
- ? __('Header image', 'tarski')
- : get_bloginfo('name'),
- $header_img_url);
-
+ if (!isset($header_img_tag)) {
+ $header_img_tag = sprintf('<img alt="%s" src="%s">',
+ get_tarski_option('display_title')
+ ? __('Header image', 'tarski')
+ : get_bloginfo('name'),
+ $header_img_url);
}
if (!(get_tarski_option('display_title') || is_front_page()))

0 comments on commit 5c47e24

Please sign in to comment.