Community Forums › Forums › Archived Forums › Design Tips and Tricks › Add a Featured Image above a Single Post
Tagged: Customizing Themes, featured image, thumbnails
- This topic has 7 replies, 3 voices, and was last updated 10 years, 1 month ago by
ParkPush.
-
AuthorPosts
-
February 15, 2013 at 12:32 pm #20553
raulcolon
MemberI want to add the featured image to blog posts so it maintains uniformity and my client does not have to upload it (because I know they will forget).
I have tried using the get_the_post_thumbnail() on my template and it does not appear although it moves the code.
I also went ahead and added the add_theme_support( 'post-thumbnails' ); to the functions file and I have not been successful.
Is there any possible way where I can include in a customized template of a blog post an image on top.
Would really appreciate the help?
February 15, 2013 at 1:30 pm #20566cdils
ParticipantHi there,
Are you wanting to add the same featured image to each (or at least most) of your posts? This plugin might be perfect:
http://wordpress.org/extend/plugins/genesis-featured-images/
Carrie
Have you been helped in this forum? Pay it forward and answer someone else’s question. I bet you’ll know the answer to at least one question. 🙂
I host a weekly WordPress-focused podcast called Office Hours. I tweet @cdils.
February 15, 2013 at 2:05 pm #20577raulcolon
MemberCarrie,
Thanks for the reply. Maybe I was not clear enough in my question.
I want each blog post to have the featured image on top of the entry title and post info box so the client does not have to insert it in the post.
Similar to what the going green seems to do.
Thanks for your help.
February 15, 2013 at 2:56 pm #20593cdils
ParticipantAh! Okay, try adding this to functions.php:
/** Add featured image above single posts */ add_action( 'genesis_before_post_content', 'cd_featured_image' ); function cd_featured_image() { if ( is_single() && has_post_thumbnail() ){ echo '<div id="featured-image">'; echo get_the_post_thumbnail($thumbnail->ID, 'thumbnail-size'); echo '</div>'; }}
Where it says "thumbnail-size", you'll want to replace that with whatever image size you've decided on for your posts. If you're not sure, look in your functions.php for something like this:
// Add new image sizes
That'll show you the name of any special image sizes declared for your theme.
If you want the photo above the post title, change the action to 'genesis_before_post_title' instead of 'genesis_before_post_content' (Here's a handy hook reference you might like: http://my.studiopress.com/docs/hook-reference/)
Cheers,
Carrie
Have you been helped in this forum? Pay it forward and answer someone else’s question. I bet you’ll know the answer to at least one question. 🙂
I host a weekly WordPress-focused podcast called Office Hours. I tweet @cdils.
February 15, 2013 at 10:57 pm #20632raulcolon
MemberPerfect code worked well.
/** Add featured image above single posts */
add_action( 'genesis_before_post_title', 'cd_featured_image' );
function cd_featured_image() {
if ( is_single() & has_post_thumbnail() ){
echo '<div id="featured-image">';
echo get_the_post_thumbnail($thumbnail->ID, 'thumbnail-size');
echo '</div>';
}
}Thanks again.
February 26, 2013 at 11:15 am #22937ParkPush
MemberAny particular reason this would break?
The error reads;Parse error: syntax error, unexpected T_ECHO in /home/toughman/public_html/wp-content/themes/switch/functions.php on line 22
<?php
// Start the engine
require_once( get_template_directory() . '/lib/init.php' );// Child theme (do not remove)
define( 'CHILD_THEME_NAME', 'Switch' );
define( 'CHILD_THEME_URL', 'http://www.studiopress.com/' );// Add Viewport meta tag for mobile browsers
add_action( 'genesis_meta', 'sample_viewport_meta_tag' );
function sample_viewport_meta_tag() {
echo '';
}// Adding full width structure
add_theme_support( 'genesis-structural-wraps', array( 'header', 'nav', 'subnav', 'inner', 'footer-widgets', 'footer' ) );/** Add featured image above single posts */
add_action( 'genesis_before_post_content', 'cd_featured_image' );
function cd_featured_image() {
if ( is_single() && has_post_thumbnail() ){
echo '';
echo get_the_post_thumbnail($thumbnail->ID, 'thumbnail-size');
echo '';
}
}// Add support for custom background
add_theme_support( 'custom-background' );// Add support for custom header
add_theme_support( 'genesis-custom-header', array(
'width' => 1152,
'height' => 120
) );/** Reposition header outside main wrap */
remove_action( 'genesis_header', 'genesis_header_markup_open', 5 );
remove_action( 'genesis_header', 'genesis_do_header' );
remove_action( 'genesis_header', 'genesis_header_markup_close', 15 ) ;add_action( 'genesis_before', 'genesis_header_markup_open', 5 );
add_action( 'genesis_before', 'genesis_do_header' );
add_action( 'genesis_before', 'genesis_header_markup_close', 15 );// Add support for 3-column footer widgets
add_theme_support( 'genesis-footer-widgets', 3 );add_filter( 'author_link', 'my_author_link' );
function my_author_link() {
return home_url( 'about/' );
}/** Register widget areas WELCOME */
genesis_register_sidebar( array(
'id' => 'welcome-text',
'name' => __( 'Welcome Text', 'genesis' ),
'description' => __( 'This is the welcome text widget.', 'themename' ),
) );/** Add the welcome text section */
add_action( 'genesis_after_header', 'custom_welcome_text' );
function custom_welcome_text() {
genesis_widget_area( 'welcome-text', array(
'before' => '',
) );
}/** Register widget areas PAGE TOP */
genesis_register_sidebar( array(
'id' => 'page-top',
'name' => __( 'Page Top', 'genesis' ),
'description' => __( 'This is the page top text widget.', 'switch' ),
) );/** Add the welcome text section */
add_action( 'genesis_before_content_sidebar_wrap', 'custom_page_top' );
function custom_page_top() {
genesis_widget_area( 'page-top', array(
'before' => '',
) );
}/** Register widget areas PAGE BOTTOM */
genesis_register_sidebar( array(
'id' => 'page-bottom',
'name' => __( 'Page Bottom', 'genesis' ),
'description' => __( 'Add content here to go below page/post content.', 'themename' ),
) );/** Add the page bottom section */
add_action( 'genesis_after_loop', 'custom_page_bottom' );
function custom_page_bottom() {
genesis_widget_area( 'page-bottom', array(
'before' => '',
) );
}// Reposition the Primary Navigation
// remove_action(‘genesis_after_header’, ‘genesis_do_nav’);
// add_action(‘genesis_before_header’, ‘genesis_do_nav’);// Reposition the Secondary navigation menu */
// remove_action( 'genesis_after_header', 'genesis_do_subnav' );
// add_action( 'genesis_before', 'genesis_do_subnav' );/*------
function custom_author_post_avatar_teaser(){
if( is_home() ){
if( get_query_var( 'author_name' ) ){
$curauth = get_userdatabylogin( get_query_var( 'author_name' ) );
}else{
$curauth = get_userdata( get_query_var( 'author' ) );
}
?><? echo "".get_avatar( get_the_author_email(), '24' ).""; ?>
Placeholder Text
//binding to the load field settings event to initialize the checkbox
jQuery(document).bind("gform_load_field_settings", function(event, field, form){
jQuery("#field_placeholder").val(field["placeholder"]);
});jQuery(function(){
$field){/* Check if the field has an assigned placeholder */
if(isset($field['placeholder']) && !empty($field['placeholder'])){
/* If a placeholder text exists, inject it as a new property to the field using jQuery */
?>
jQuery('#input__').attr('placeholder','');
});
<?php
}
February 26, 2013 at 12:07 pm #22941cdils
ParticipantWhat's on line 22 of your functions.php file? Not sure if the lines/spacing are the same on the code pasted above, but try removing your empty echo ''; statements.
Have you been helped in this forum? Pay it forward and answer someone else’s question. I bet you’ll know the answer to at least one question. 🙂
I host a weekly WordPress-focused podcast called Office Hours. I tweet @cdils.
February 26, 2013 at 12:20 pm #22944ParkPush
MemberThat's weird. The 's were removed when I pasted. Line 22 is;
echo ‘’;
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.