From 999f082121dba17ac0d9547ab3c779810392bc82 Mon Sep 17 00:00:00 2001 From: Martin Lormes Date: Wed, 11 Jan 2012 23:35:06 +0100 Subject: [PATCH] added option to display 'featured image' in the header, not in the post content --- app/templates/loop.php | 4 ++-- functions.php | 3 +++ index.php | 2 +- library/classes/options.php | 4 ++++ library/helpers/admin_helper.php | 3 ++- library/helpers/template_helper.php | 12 ++++++++++++ 6 files changed, 24 insertions(+), 4 deletions(-) diff --git a/app/templates/loop.php b/app/templates/loop.php index c68ab37..da68501 100644 --- a/app/templates/loop.php +++ b/app/templates/loop.php @@ -3,7 +3,7 @@ if (has_post_format('aside') || (get_tarski_option('asidescategory') && in_category(get_tarski_option('asidescategory')))) { // Aside loop ?>
id="p-">
- +
@@ -25,7 +25,7 @@
- +
diff --git a/functions.php b/functions.php index fb9554d..6088750 100644 --- a/functions.php +++ b/functions.php @@ -153,6 +153,9 @@ // 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); // Post types diff --git a/index.php b/index.php index 20b1aa0..a43e59d 100644 --- a/index.php +++ b/index.php @@ -16,7 +16,7 @@
- +
diff --git a/library/classes/options.php b/library/classes/options.php index 7eb4488..0220484 100644 --- a/library/classes/options.php +++ b/library/classes/options.php @@ -33,6 +33,8 @@ class TarskiOptions { var $asidescategory; var $centred_theme; var $swap_sides; + var $swap_title_order; + var $featured_header; var $tags_everywhere; var $show_categories; var $show_authors; @@ -83,6 +85,7 @@ function set_defaults() { 'centred_theme' => true, 'swap_sides' => false, 'swap_title_order' => false, + 'featured_header' => false, 'tags_everywhere' => true, 'show_categories' => true, 'show_authors' => true, @@ -124,6 +127,7 @@ function tarski_options_update() { $this->centred_theme = (bool) $_POST['centred_theme']; $this->swap_sides = (bool) $_POST['swap_sides']; $this->swap_title_order = (bool) $_POST['swap_title_order']; + $this->featured_header = (bool) $_POST['featured_header']; unset($this->deleted); } diff --git a/library/helpers/admin_helper.php b/library/helpers/admin_helper.php index 62a709e..44e56a1 100644 --- a/library/helpers/admin_helper.php +++ b/library/helpers/admin_helper.php @@ -316,7 +316,8 @@ function tarski_miscellaneous_options() { 'tags_everywhere' => __('Show tags everywhere', 'tarski'), 'centred_theme' => __('Centrally align the theme', 'tarski'), 'swap_sides' => __('Switch column order', 'tarski'), - 'swap_title_order' => __('Reverse document title order', 'tarski')); + 'swap_title_order' => __('Reverse document title order', 'tarski'), + 'featured_header' => __('Featured images in header', 'tarski')); foreach ($checkboxes as $name => $label) $output .= tarski_option_checkbox($name, $label) . "\n\n"; diff --git a/library/helpers/template_helper.php b/library/helpers/template_helper.php index 4aac8a6..598c761 100644 --- a/library/helpers/template_helper.php +++ b/library/helpers/template_helper.php @@ -284,6 +284,16 @@ function tarski_headerimage() { $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 (!$header_img_url) return; $header_img_tag = sprintf('%s', @@ -292,6 +302,8 @@ function tarski_headerimage() { : get_bloginfo('name'), $header_img_url); + } + if (!(get_tarski_option('display_title') || is_front_page())) $header_img_tag = sprintf( '%s',