WordPress.org

Ready to get started?Download WordPress

Forums

User Submitted Posts
[resolved] how to set default feature image If user do not upload a photo. (3 posts)

  1. jiyuu19th
    Member
    Posted 4 months ago #

    how to set default feature image (561x264px) If user do not upload a photo.

    http://wordpress.org/plugins/user-submitted-posts/

  2. Jeff Starr
    Member
    Plugin Author

    Posted 4 months ago #

    Adding to the technique described at WP-Mix:

    // @ http://wp-mix.com/set-attachment-featured-image/
    add_filter('the_content', 'set_featured_image_from_attachment');
    function set_featured_image_from_attachment($content) {
    	global $post;
    	if (has_post_thumbnail()) {
    		// display the featured image
    		$content = the_post_thumbnail() . $content;
    	} else {
    		// get & set the featured image
    		$attachments = get_children(array(
    			'post_parent' => $post->ID,
    			'post_status' => 'inherit',
    			'post_type' => 'attachment',
    			'post_mime_type' => 'image',
    			'order' => 'ASC',
    			'orderby' => 'menu_order'
    		));
    		if ($attachments) {
    			foreach ($attachments as $attachment) {
    				set_post_thumbnail($post->ID, $attachment->ID);
    				break;
    			}
    			// display the featured image
    			$content = the_post_thumbnail() . $content;
    		}
    		// NEW STUFFS
    		else {
    			$default_image = 'featured-image-default.jpg';
    			$content = $default_image . $content;
    		}
    	}
    	return $content;
    }

    Same usage instructions as explained at the original post.

  3. jiyuu19th
    Member
    Posted 4 months ago #

    thank so much jeff, but it not work for me.
    I'll try to find another way.

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.