ThemeShaper Forums » Thematic

[closed]

Featured Image: Setting a Default Image

(5 posts)
  • Started 7 years ago by robYardman
  • Latest reply from robYardman
  • This topic is resolved
  1. I'm just curious if anyone has code for setting a default featured image if a user does not specify one?

    I have a contributor based website and they do not always set a featured image. I'd like to set a default image to dummy proof the problem.

    If anyone has Thematic compatible code to do this I would much appreciate it.

    Posted 7 years ago #
  2. you'd need to filter thematic_post

    function kia_post($post) {
    	global $thematic_content_length;
    
    	if ( strtolower($thematic_content_length) == 'excerpt') {
    			$post = '';
    			$post .= get_the_excerpt();
    			$post = apply_filters('the_excerpt',$post);
    			if ( apply_filters( 'thematic_post_thumbs', TRUE) ) {
    				$post_title = get_the_title();
    				$size = apply_filters( 'thematic_post_thumb_size' , array(100,100) );
    				$attr = apply_filters( 'thematic_post_thumb_attr', array('title'	=> 'Permalink to ' . $post_title) );
    				if ( has_post_thumbnail() ) {
    					$post = '<a class="entry-thumb" href="' . get_permalink() . '" title="Permalink to ' . get_the_title() . '" >' . get_the_post_thumbnail(get_the_ID(), $size, $attr) . '</a>' . $post;
    				} else {
    					$post = '<a class="entry-thumb" href="' . get_permalink() . '" title="Permalink to ' . get_the_title() . '" ><img src="' . get_stylesheet_directory_uri(). '/images/default-thumbnail.png"/></a>' . $post;
    				}
    			}
    		}
    		return $post;
    }
    add_filter('thematic_post','kia_post');

    untested, so beware of typos

    Posted 7 years ago #
  3. Sweet I'll test this afternoon.

    Thanks htv!

    Posted 7 years ago #
  4. if that worked, please mark as resolved

    Posted 7 years ago #
  5. Worked just needed css on img "attachment-100x100 wp-post-image"

    // Default Feature Image
    function kia_post($post) {
    	global $thematic_content_length;
    
    	if ( strtolower($thematic_content_length) == 'excerpt') {
    			$post = '';
    			$post .= get_the_excerpt();
    			$post = apply_filters('the_excerpt',$post);
    			if ( apply_filters( 'thematic_post_thumbs', TRUE) ) {
    				$post_title = get_the_title();
    				$size = apply_filters( 'thematic_post_thumb_size' , array(100,100) );
    				$attr = apply_filters( 'thematic_post_thumb_attr', array('title'	=> 'Permalink to ' . $post_title) );
    				if ( has_post_thumbnail() ) {
    					$post = '<a class="entry-thumb" href="' . get_permalink() . '" title="Permalink to ' . get_the_title() . '" >' . get_the_post_thumbnail(get_the_ID(), $size, $attr) . '</a>' . $post;
    				} else {
    					$post = '<a class="entry-thumb" href="' . get_permalink() . '" title="Permalink to ' . get_the_title() . '" ><img class="attachment-100x100 wp-post-image" src="' . get_stylesheet_directory_uri(). '/images/featured-image.png"/></a>' . $post;
    				}
    			}
    		}
    		return $post;
    }
    add_filter('thematic_post','kia_post');
    Posted 7 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.