WP Smith

Creating WordPress & Genesis Websites Since 2010

  • Home
  • About
  • Services
  • Blog
  • Contact

Mar 09 2011

StudioPress's Genesis Featured Post Glitch with Show Content

Recently in working with the Featured Posts Widget for my sites (and then seeing this post in the StudioPress forums), I've learned that there is a "glitch" in its code or in the use of the widget. Either way, the code should be updated to protect against user error.

Scenario: User creates a post. Inserts an image into the post so that when it appears as a single post page, the image appears as the user desires. Then they set that same image as the featured image. So let's say that they set the image on the first line as a class of alignleft.

Now if they were to select to show the content (and show content limit may also cause problems depending on where the image is and how it gets pulled into the_content();), as in all of the content, then that's where the problem arises.

Featured Posts Widget SettingsThe featured posts shows the content which includes the image that is set in the post. So now there are two images showing as can be seen here.
Featured Posts Front Page

Furthermore, there are several widgets out there that extend the Genesis Featured Post widget (or vice versa).

Solution: But the problem can be prevented in two ways.

First, as a band-aid of sorts, there are two solutions that we can use as users without hacking core, because we should never hack core. First, is always use Show Content Limit and set accordingly (trial & error) or use Excerpt. Second, do not insert the picture on your post and add this code to your functions.php file, which will place the image at the top of the post aligned to the left. If you want to align it to the right simply change alignleft to alignright or aligncenter to align center.

[php]add_action('genesis_before_post_content','add_featured_image');
add_image_size('Medium 16x9', 400, 225, TRUE);
function add_featured_image(){
if (is_single() && (get_post_type() != 'attachment')) {
genesis_image("format=html&size=Medium 16x9&attr=class=alignleft");
}
}[/php]

Medium 16x9 can be changed to whatever title description you'd like. If you change the description in add_image_size, then change it in genensis_image. And the dimensions can be changed to whatever you'd like where width = 400 and height = 225. genesis_add_image_size($name, $width = 0, $height = 0, $crop = FALSE); is used but is also deprecated probably because WordPress has image_size( $name, $width = 0, $height = 0, $crop = FALSE);.

Second, the solution can be solved by StudioPress in the core of Genesis by changing the code in featured-post-widget.php at about line 58 (and probably featured-page-widget.php at about line 44). The original code has:

[php]if(!empty($instance['show_image'])) :
printf( '<a href="%s" title="%s">%s</a>', get_permalink(), the_title_attribute('echo=0'), esc_attr( $instance['image_alignment'] ), genesis_get_image( array( 'format' => 'html', 'size' => $instance['image_size'] ) ) );
endif;
[/php]

And it could be changed to the following so it doesn't show the image to eliminate user confusion. While it doesn't have to be changed, it is the most user-friendly approach.

[php]if(!empty($instance['show_image'])) :
if(!empty($instance['show_content'])) :
if($instance['show_content'] == 'content') :
printf( '<a href="%s" class="%s" title="%s">%s</a>', get_permalink(), the_title_attribute('echo=0'), esc_attr( $instance['image_alignment'] ), genesis_get_image( array( 'format' => 'html', 'size' => $instance['image_size'] ) ) );
endif;
endif;
endif;
[/php]

Written by Travis Smith · Categorized: Genesis, Tutorials

StudioPress Premium WordPress Themes     WP Engine Managed WordPress Hosting

What can I do for you!?

Custom Development

We develop plugins by determining both business/functional and technical requirements, following WordPress development best practices, and using agile methodology to ensure you get the best solution.

Consulting

Have questions? Need a reliable developer to consult? Please contact us today!

Customized Theme

We can customize your theme or child theme, or create a child theme for you based on your needs while enhancing the performance of every individual attribute.

Customized Plugin

We can customize your plugins, extend plugins (e.g., Gravity Forms, Jetpack, Soliloquy) based on your needs ensuring security, performance, and positive business impact.

Contact Us

About Travis Smith

As a WordPress enthusiast, developer, and speaker, Travis writes about what he learns in WordPress trying to help other WordPress travelers, beginners and enthusiasts with tutorials, explanations, & demonstrations.

Comments

  1. Nick the Geek says

    March 9, 2011 at 9:59 am

    This is a good solution for automatically inserting the image into all posts the same way. This is the only solution if someone wishes to show the entire post content with the featured image via the widget or in the content archives. Generally this isn’t required and should not be built into the framework, since it can eb easily done via a child theme and limits flexibility within the framework if built in.

    Reply
  2. Linh Nguyen says

    September 13, 2011 at 11:51 pm

    Hi I used the widget on my homepage and the featured image cannot display inline with the post. I don’t know why. Please help.

    Reply
    • Travis Smith says

      September 14, 2011 at 4:57 pm

      Hi, please use the StudioPress Support forums, and when you do, always include a link to your site.

      Reply
  3. sheila says

    April 11, 2013 at 7:19 am

    Hi,
    I’m putting an agentpress website together for a friend –
    1. First – how can I choose which featured images are shown in the featured widget section – it now takes the most recently entered listings and shows those – the only control I have is how many.
    2. For the genesis slider – it takes the featured image and shows that – for the pictures of homes where I can’t get the picture big enough – what code can I alter or enter to have each picture in the slider centered.
    3. Last question! I like the default color blue. Where can I override the background color – not on the inner section but around the inner section – when I enter the color in the background it is changed to the default.
    Thanks!!

    Reply
  4. Alexis Villegas says

    May 4, 2013 at 2:21 am

    Thank you so much for this tip. After a few hours researching how to fix the problem I stumble upon your site and got the solution. Mu problem was that I just wanted to feature image to display on top of the post and I successfully got it by just using this part of the code above:

    add_action(‘genesis_before_post_content’,’add_featured_image’);
    add_image_size(‘post-image’, 700, 389, TRUE);
    function add_featured_image(){
    if (is_single() && (get_post_type() != ‘attachment’)) {
    genesis_image(“format=html&size=post-image&attr=class= aligncenter”);
    }
    }
    So my question now is, how do I modify this code to do the same in pages? I tried the following but it didn’t work:

    add_action(‘genesis_before_post_content’,’add_featured_image’);
    add_image_size(‘post-image’, 700, 389, TRUE);
    function add_featured_image(){
    if (is_single() && is_page && (get_post_type() != ‘attachment’)) {
    genesis_image(“format=html&size=post-image&attr=class= aligncenter”);
    }
    }

    Any help on how to add the is_page value to the if () statement would be really appreciated. Thanks!

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  • Twitter
  • Facebook
  • LinkedIn
  • Google+
  • RSS

Copyright © 2025 � WP Smith on Genesis on Genesis Framework � WordPress � Log in