Skip to content

Commit

Permalink
Add option to display featured post images in the header.
Browse files Browse the repository at this point in the history
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
beastaugh committed Apr 22, 2012
1 parent 954469c commit 5c47e24
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 20 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Expand Up @@ -2,6 +2,7 @@


### Version 3.2.0 ### Version 3.2.0


* Added option to display featured post images in the header.
* Moved language files to `/languages` directory. * Moved language files to `/languages` directory.
* Added POT file to theme files in `languages` directory. * Added POT file to theme files in `languages` directory.
* Replaced use of deprecated `add_custom_image_header` function. * Replaced use of deprecated `add_custom_image_header` function.
Expand Down
16 changes: 12 additions & 4 deletions functions.php
Expand Up @@ -156,10 +156,18 @@


// Post thumbnails; change these settings via a child theme or plugin // Post thumbnails; change these settings via a child theme or plugin
add_theme_support('post-thumbnails'); add_theme_support('post-thumbnails');
if (get_tarski_option('featured_header'))
set_post_thumbnail_size(HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT, true); if (get_tarski_option('featured_header')) {
else set_post_thumbnail_size(HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT, true);
set_post_thumbnail_size(150, 150, false); } 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 // Post types
add_theme_support('post-formats', array('aside')); add_theme_support('post-formats', array('aside'));
Expand Down
2 changes: 1 addition & 1 deletion library/helpers/admin_helper.php
Expand Up @@ -317,7 +317,7 @@ function tarski_miscellaneous_options() {
'centred_theme' => __('Centrally align the theme', 'tarski'), 'centred_theme' => __('Centrally align the theme', 'tarski'),
'swap_sides' => __('Switch column order', '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')); 'featured_header' => __('Display featured images in header', 'tarski'));


foreach ($checkboxes as $name => $label) foreach ($checkboxes as $name => $label)
$output .= tarski_option_checkbox($name, $label) . "\n\n"; $output .= tarski_option_checkbox($name, $label) . "\n\n";
Expand Down
35 changes: 20 additions & 15 deletions library/helpers/template_helper.php
Expand Up @@ -277,32 +277,37 @@ function _tarski_asset_output($type, $assets) {
* @uses user_trailingslashit * @uses user_trailingslashit
* @uses home_url * @uses home_url
* *
* @global object $post
*
* @return string * @return string
*/ */
function tarski_headerimage() { function tarski_headerimage() {
global $post; global $post;

if (!get_theme_mod('header_image')) return; if (!get_theme_mod('header_image')) return;


$header_img_url = get_header_image(); $header_img_url = get_header_image();


// inspired by twentyeleven if (get_tarski_option('featured_header') &&
if ( get_tarski_option('featured_header') && is_singular($post) &&
is_singular() && has_post_thumbnail($post->ID)) {
has_post_thumbnail( $post->ID ) && $image_size = array(HEADER_IMAGE_WIDTH, HEADER_IMAGE_WIDTH);
( /* $src, $width, $height */ $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), array( HEADER_IMAGE_WIDTH, HEADER_IMAGE_WIDTH ) ) ) && $image_id = get_post_thumbnail_id($post->ID);
$image[1] >= HEADER_IMAGE_WIDTH ) $image = wp_get_attachment_image_src($image_id, $image_size);
// Houston, we have a new header image!
$header_img_tag = get_the_post_thumbnail( $post->ID, 'post-thumbnail' ); if ($image[1] >= HEADER_IMAGE_WIDTH) {
else { $header_img_tag = get_the_post_thumbnail($post->ID, $image_size);
}
}


if (!$header_img_url) return; if (!$header_img_url) return;


$header_img_tag = sprintf('<img alt="%s" src="%s">', if (!isset($header_img_tag)) {
get_tarski_option('display_title') $header_img_tag = sprintf('<img alt="%s" src="%s">',
? __('Header image', 'tarski') get_tarski_option('display_title')
: get_bloginfo('name'), ? __('Header image', 'tarski')
$header_img_url); : get_bloginfo('name'),

$header_img_url);
} }


if (!(get_tarski_option('display_title') || is_front_page())) if (!(get_tarski_option('display_title') || is_front_page()))
Expand Down

0 comments on commit 5c47e24

Please sign in to comment.