Category vs Single Featured Images Ideas – Agency

Community Forums Forums General Discussion Category vs Single Featured Images Ideas – Agency

This topic is: resolved

This topic contains 10 replies, has 4 voices, and was last updated by  slydawgg 1 year, 2 months ago.

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #58865

    slydawgg
    Participant
    Post count: 20

    Greetings! You guys have been helpful to me in the past, so I thought I would turn to you guys once more, as I feel like I may have reached out to Bill Erickson (AMAZING TUTORIALS) too many times. Anyways, I have this small problem that I feel like I am close to resolving but can’t get the right combination yet.

    One of Bill’s tutorials helped me figure out how to show a default “sample image” on Category pages (http://www.billerickson.net/default-image-for-post-thumbnails/#comment-12406), so I was able to get this:

    http://bae.uncg.edu/directory/employees/economics-employees

    Unfortunately when I click on a post that does has a Featured image, it now displays twice (one is the size of the original Featured Image, while the other is a thumbnail version):

    http://bae.uncg.edu/directory/employees/economics-employees/doe-john/

    Personally, on the Single Post page, I would like for the Original Size Featured image to display, but if I can only get the thumbnail to display – that is fine also. Basically, I just want 1 image to show up on the Single/is_single pages.

    \\\\\\\\\\\\\\
    \\\\\\\\\\\\\\ I
    have tried a few different snippets of code, as well as tried to put different things within Simple Hooks &
    functions.php.

    So here are the things I have tried thus far = I have this code in functions.php at the moment
    https://gist.github.com/anonymous/6343468

    and went into the Simple Hooks under genesis_post_content, I have:
    <a href="<?php the_permalink();?>"><?php if(has_post_thumbnail()) the_post_thumbnail('thumbnail'); else echo be_no_thumbnail('thumbnail'); ?></a>

    So far everything is great and perfect when I am on any Category Page.
    There is just one small exception. When I visit a single post page, it displays 2 of the same images but in different sizes –

    • at the top at full size (class=post-photo) which has always been there
    • after the title of the Post but before the post content but at 150×150

    What’s the best way to say:
    Show thumbnail of Featured image on Category Page, unless there isn’t one (then show a default image instead), but on a Single Post page, show full size featured image and no thumbnail?
    \\\\\\\\\\\\\\
    \\\\\\\\\\\\\\
    This is not a “live” site and just has fake data in it, but I am sharing with you in hopes you can point me in the right direction

    http://bae.uncg.edu/directory/employees/economics-employees
    #59061

    slydawgg
    Participant
    Post count: 20

    I’ve done some more to the code, and am getting better results – but still cannot figure out how to remove the 2nd thumbnail on the actual Single Post Page.

    My current code:

    add_action('genesis_post_content', 'be_no_thumbnail');
    function be_no_thumbnail( $size ) {
    if ( is_single() ) return '';
    	if ( is_category() )
    return '<img width="'.get_option($size.'_size_w').'" height="'.get_option($size.'_size_h').'" src="'.get_bloginfo('stylesheet_directory').'/images/no-image.png" />';
    
    }
    
    add_action('genesis_after_post_title', 'fac_image');
    function fac_image( $size ) {
    	
    	
    if ( is_category() ) return;
    if ( $image = genesis_get_image( 'format=url&size=post-image' ) ) {
    printf( '<a href="%s" rel="bookmark"><img class="post-photo" src="%s" alt="%s" /></a>', get_permalink(), $image, the_title_attribute( 'echo=0' ) );
    }
    

    Please, does anybody know what to do? Is there something I can do with the “genesis_after_post_content” tag or some where else?

    Any assistance would be greatly appreciated!

    #59182

    cehwitham
    Participant
    Post count: 396

    I can’t see an example as I’m getting page not found off your links.

    I think you need a conditional to check if the post has an image and if not then output the default. See the example here:

    http://codex.wordpress.org/Function_Reference/has_post_thumbnail


    Twitter: cehwitham Web: cehwitham.com

    #59188

    slydawgg
    Participant
    Post count: 20

    Chris, thanks for assistance and I will give your advice another go today as I think I tried this already without success.
    Also, I republished the ” John Doe” link found above if you want to see what I’m seeing.

    #59194

    cehwitham
    Participant
    Post count: 396

    Looking at the link you provided. It looks as if your theme might be outputting images on single pages by default. Does one of the images remain if you remove all of your code?

    Chris


    Twitter: cehwitham Web: cehwitham.com

    #59210

    AC
    Blocked
    Post count: 7712

    @Slydawgg, Brad Dalton did a tutorial on how auto set the featured image post thumbnails – http://wpsites.net/wordpress-tips/auto-set-featured-image/. Have you seen this?

    #59561

    slydawgg
    Participant
    Post count: 20

    Thanks for your advice so far @cehwitham and @anitac. I may not have fully explained myself before. The Featured Image portion of the single_post pages don’t seem to be the problem.
    I think the problem lays within the fact I am trying to display “default blank images” when a post does not have a featured image attached to it. What do I mean by this?

    My best example is this:
    If I go to the Category Page = http://goo.gl/mhcVi2 you should see 2 Posts, one that actually has a Featured image (the rabbit) and one that does not have any image connected to it – so it defaults to a blank image (blue image called “no-image”)

    If I go to the Single/Individual Post without an image http://goo.gl/nUrZyp no image appears, which is PERFECT
    If I go to the Single/Individual Post with an image http://goo.gl/U3luni I see both the original Featured Image and the little 150×150 thumbnail from the Category Page. This thumbnail I would like gone on the Single/Individual Post Page.

    I tried the above ideas, and they provided me some interesting information for a few other issues I had, except they were not able to resolve this particular issue. I had hoped I could go into the single.php page template for the Agency Theme and make the adjustments, but it doesn’t appear I can do that within Genesis.

    My current code consists of a few things:

    /*adds featured image is one is there*/
    function agency_post_image() {
    if ( is_category() ) return;
    	if ( $image = genesis_get_image( 'format=url&size=post-image' ) ) {
    	printf( '<a href="%s" rel="bookmark"><img class="post-photo" src="%s" alt="%s" /></a>', get_permalink(), $image, the_title_attribute( 'echo=0' ) );
    	}
    }
    
    /*adds default image if nothing exists*/
    add_action('genesis_post_content', 'be_no_thumbnail');
    function be_no_thumbnail( $size ) {
    	if ( is_category() )
    return '<img width="'.get_option($size.'_size_w').'" height="'.get_option($size.'_size_h').'" src="'.get_bloginfo('stylesheet_directory').'/images/no-image.jpg" />';
    	
    }
    
    /*the hope is on Single Post, add Featured Image, remove thumbnail action*/
    	if ( ! is_singular() ) {
    add_action( 'genesis_before_post_content', 'agency_post_image' );
    remove_action('genesis_post_content', 'be_no_thumbnail');
    	}
    
    /*the hope is on Single Post, add Featured Image, remove thumbnail action*/
    if ( ! is_single() ) {
    remove_action('genesis_post_content', 'be_no_thumbnail');
    	}

    I hope this makes sense…

    #59576

    billerickson
    Participant
    Post count: 17

    I’ll be honest, I don’t see how the code you posted is actually working.

    1. be_no_thumbnail(), in the way you’re using it, should be echo’ing the output, not returning it.
    2. be_no_thumbnail() has an is_category() conditional, which means it can’t be running on the single posts.

    I think you’re over complicating things. What happens if you remove all this code? What is the default display of the single post? Then what are the features you’re looking to add?

    If the only feature you want to add is a fallback for the archive page, add the following to your theme’s functions.php file: https://gist.github.com/billerickson/6381350

    I duplicated the genesis_do_post_image() function as be_post_image_with_fallback(). I then added a bit to it (right before the !empty( $img) ) that adds the fallback if there’s no image. I then removed the genesis_do_post_image() function from its hook and replaced it with our new one. I also defined the fallback image function.

    This could also be done with less code by filtering genesis_get_image args and settings the ‘fallback’ to your fallback image. But that would be a bit more complicated and outside the scope of the tutorial you linked to previously

    #59578

    slydawgg
    Participant
    Post count: 20

    @Bill – I’m sure I am over complicating things, as I have stared at this for a few days now.
    The only thing about this particular solution (although much more simple than what I was trying to do), when I am on the Single Page, I had hoped to be able to get rid of the 150×150 thumbnail and actually display the Full sized Featured Image (if it exists). If there wasn’t a Featured Image, nothing has to exists (even the fallback image).

    Category Page:
    thumbnails of featured images or fallback image

    Single Posts:
    Full size featured image only; no thumbnail…

    #59579

    billerickson
    Participant
    Post count: 17

    Where is the thumbnail coming from on the single post? That’s not a Genesis feature. My guess is that the Agency theme is adding that. Find the function that’s outputting the thumbnail on the single post and change the size from ‘thumbnail’ to ‘full’

    #60477

    slydawgg
    Participant
    Post count: 20

    @Bill – You were correct a few different times with this one – The code was over complicated and the Thumbnail size…

    > Agency was grabbing a random thumbnail size, as well as WP was still set at 150×150. Once you reminded me about Agency’s thumbnail size I switched that… Almost got frustrated, until I realized something that I want to smack myself for…
    > Over complicating things = because WP has imported those images in while the settings were 150×150, the “thumbnail” image was set at 150×150 even though Agency had been changed. Once I deleted a sample out of the Media library and re-uploaded it – worked like a charm.

    Thanks for everybody who helped with this – Genesis & WordPress community, as always, rocks!

Viewing 11 posts - 1 through 11 (of 11 total)

The topic ‘Category vs Single Featured Images Ideas – Agency’ is closed to new replies.