[Theme: Twenty Eleven] Advanced header image techniques
-
So I was fiddling around with the Twenty Eleven theme. I was turning it into my own custom theme (as it makes for a great starting point). As anyone can figure out, Twenty Eleven has the following code pertaining to header images in
header.php
:<?php // Check to see if the header image has been removed $header_image = get_header_image(); if ( $header_image ) : // Compatibility with versions of WordPress prior to 3.4. if ( function_exists( 'get_custom_header' ) ) { // We need to figure out what the minimum width should be for our featured image. // This result would be the suggested width if the theme were to implement flexible widths. $header_image_width = get_theme_support( 'custom-header', 'width' ); } else { $header_image_width = HEADER_IMAGE_WIDTH; } ?> <a href="<?php echo esc_url( home_url( '/' ) ); ?>"> <?php // The header image // Check if this is a post or page, if it has a thumbnail, and if it's a big one if ( 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! echo get_the_post_thumbnail( $post->ID, 'post-thumbnail' ); else : // Compatibility with versions of WordPress prior to 3.4. if ( function_exists( 'get_custom_header' ) ) { $header_image_width = get_custom_header()->width; $header_image_height = get_custom_header()->height; } else { $header_image_width = HEADER_IMAGE_WIDTH; $header_image_height = HEADER_IMAGE_HEIGHT; } ?> <img src="<?php header_image(); ?>" width="<?php echo $header_image_width; ?>" height="<?php echo $header_image_height; ?>" alt="<?php the_title(); ?>" /> <?php endif; // end check for featured image or standard header ?> </a> <?php endif; // end check for removed header image ?>
Now, I want to have it such that if I do not have a custom, site-wide header enabled, WordPress will grab the post-thumbnail from the most recent article that has a featured image set to use as the header image.
How would I do that? I’m not good enough with php to just invent something. I tried adding stuff to the default code, but it just made the header image stop displaying…
Viewing 8 replies - 1 through 8 (of 8 total)
Viewing 8 replies - 1 through 8 (of 8 total)
- The topic ‘[Theme: Twenty Eleven] Advanced header image techniques’ is closed to new replies.