• Resolved Avantart

    (@avantart)


    Hello!

    I started to test your theme on a copy pf my working-blog. The test is here: https://www.urbanistan.de/wordWock/

    I understand the use of the featured image at archive pages, but I have some posts which have no featured image. In this case one half of the “post- row” is empty whith a hover-background.

    What can I do to define a default featured image in these cases?

    Thanks in advance!

    Connie

Viewing 12 replies - 1 through 12 (of 12 total)
  • Theme Author Ben Sibley

    (@bensibley)

    Hi Connie,

    Thanks for using Tracks!

    There isn’t a built-in way to define a default Featured Image. However, this could be done with a child theme by modifying the featured image function used in Tracks. Are comfortable working with child themes and PHP?

    Thread Starter Avantart

    (@avantart)

    Hi Ben,

    thank you for your fast answer, I am happy about that!

    I know about PHP and childthemes.

    Well, I once did this to add a default thumbnail to the posts in an archive page:

    I added this snippet in functions.php:

    add_filter( 'post_thumbnail_html', 'my_post_thumbnail_html' );
    function my_post_thumbnail_html( $html ) {
    
    	if ( empty( $html ) )
    		$html = '<img src="' . trailingslashit( get_stylesheet_directory_uri() ) . 'defaulthumb.png' . '" alt="blabla" title="blabla" class="alignleft" />';
    	return $html;
    }

    but this does not work in your theme. I am sure the naming is different, can you help me out?

    Theme Author Ben Sibley

    (@bensibley)

    Excellent, yes here is what needs to be done:

    Check out the ct_tracks_featured_image function on line 281 of the functions.php file. That function is used to handle the Featured Images and all the different variations of it.

    If you copy that function into your child theme, due to the function_exists() check in Tracks, your version of the function will be used instead. On line 299, you’ll see a check for the featured image with has_post_thumbnail(), you can follow that up with an else statement to supply a default featured image.

    When defining the default featured image, set $image to the URL of the image and set $has_image to true to use the image.

    Thread Starter Avantart

    (@avantart)

    Hallo Ben,

    I get the default featured image, but in contrary to the “normal” featured images, I get that only one time.
    Somewhere must be leak in my thinking ;=(

    function ct_tracks_featured_image() {
        global $post;
        $has_image = false;
        $premium_layout = get_theme_mod('premium_layouts_setting');
    	$defaultthumb = get_bloginfo( 'stylesheet_directory' ) . '/images/spitzweg.jpg';	
    
    if (has_post_thumbnail() ) {
      if( ( is_archive() || is_home() ) && $premium_layout != 'full-width' && $premium_layout != 'full-width-images' ) {
                $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'large' );}
    			else
    			{$image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' );}
        $image = $image[0];
    	$has_image = true;
    } else
    {$image = $defaultthumb;
    $has_image = true;
    }
     if ($has_image == true) {....}

    Please see it here at https://www.urbanistan.de/wordWock/

    the first entry without f.i. has the default image, the other following ones not…

    I would be grateful if you give me a kick to see what I did wrong ;=

    Theme Author Ben Sibley

    (@bensibley)

    Hmm that is strange, the other Posts have the “has-post-thumbnail” class added to them. This means WordPress is not using the default Featured Image because it believes they have one, and then gets an image that isn’t there.

    This isn’t happening for your newest post without a featured image, and it is also not a problem for much older posts. For instance, I checked on pages 30 and 70 of your archives and the default featured image is showing up.

    Is there anything different about the Posts recently back to page 10 on your site? Try visiting one and simply updating it to see if this makes any difference.

    Thread Starter Avantart

    (@avantart)

    Ben,
    thank you for the fast answer. I must say I did not experience such a good support in the last time!

    I tested. I changed some posts (changing category, deleting second category etc.) and updated, f.e. the post with the ID 27806

    no change in the behaviour

    this is something I really do not understand, all posts were imported when I duplicated the installation in order to test and work on new theme for the blog.

    If you want I might send you the passwort for the backend and the FTP, as this is no productive installation, just a test…

    Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    If you want I might send you the passwort for the backend and the FTP, as this is no productive installation, just a test…

    Please don’t do that, that level of access is a bad idea and I am sure that Ben would not request that. It’s not safe and is something that is actively discouraged here.

    Theme Author Ben Sibley

    (@bensibley)

    Okay it really is a strange error. I have a few guesses:

    The issue could be a result of the new function. Try removing the function and see if the divs containing each post still have the has-post-thumbnail even when they don’t actually have a featured image.

    If that doesn’t work, try using this plugin to regenerate your images.

    Otherwise, something may have happened during the import process that is causing this error, and it might not be an issue on your live site

    Thread Starter Avantart

    (@avantart)

    Ben, I toook off the function and checked the HTML of the elements without featured images, there I see f.e.

    with or without the function, the variable $image is empty..
    ....
    <div class="post publish author-20w0rdw0ck post-27806 format-standard has-post-thumbnail category-baltische-traditionen post_tag-craft-camp excerpt even excerpt-4">
    	<a class="featured-image-link" href="https://www.urbanistan.de/wordWock/craft-camp-7-7-heimtali-und-viljandi/"><div class='featured-image lazy lazy-bg-image' data-background=''></div></a>

    data-background is emtpy, the variable $image is empty

    and I regenerated the thumbnails… exact 699 images in the media storage…

    at page 70, the post “kreta 79” which also has no featured image, shows this HTML:

    data-background='https://www.urbanistan.de/wordWock/wp-content/themes/wordWock/images/spitzweg.jpg'>

    the variable is not empty there..

    I will think about all this, and maybe run some tests at the productive website tomorrow.. (as it is hot here, site visitors will be in the pool and not at the monitor…)

    Theme Author Ben Sibley

    (@bensibley)

    Okay sounds good. Give it a shot on the live site and let me know how it goes.

    Thread Starter Avantart

    (@avantart)

    Hello Ben,

    I installed Tracks and the child theme at my original blog and in live preview I could immediately see that everything is working as it should.
    I am so happy and I am so grateful for the great support which you give!

    Let me tell you that that level of support which you offer is not usual! I am in web design since 1993 and I experienced a lot!

    Now I have to solve some other topics which I want to realize with your theme:
    no featured image (if default one) on single posts, that will be easy
    to move the sidebar up in an archive page… in the moment it sits below the content and that I will change

    I am glad, glad, satisfied, you deserve a bouquet of flowers for your patience and assistance!

    Connie

    Theme Author Ben Sibley

    (@bensibley)

    Haha well I’m happy to help. So glad that the images worked correctly on the live site ??

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘What if no featured image?’ is closed to new replies.