1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

[HELP] U-Design Automatic Featured Image/Post Thumbnail

Discussion in 'Blogging' started by 10zen, Dec 30, 2013.

  1. 10zen

    10zen Regular Member

    Joined:
    Feb 26, 2010
    Messages:
    428
    Likes Received:
    194
    Occupation:
    IM Entrepreneur
    Location:
    World with Infinite Possibilities
    U-Design needs featured images to be assigned manually.
    I want to show first post image as post thumbnail in post excerpts.

    I used some codes found online but it seems to not work properly, puts some "Edit" text
    before excerpts in my localhost wp. Probably interferring with themes code.

    Any help would be appreciated!
     
  2. 10zen

    10zen Regular Member

    Joined:
    Feb 26, 2010
    Messages:
    428
    Likes Received:
    194
    Occupation:
    IM Entrepreneur
    Location:
    World with Infinite Possibilities
    Anybody? Just need to activate/set first post image as post thumbnail.
    I'm sure there are many wp users and coders here.

    Would appreciate the help.
     
  3. srashtaa

    srashtaa Registered Member

    Joined:
    Dec 26, 2013
    Messages:
    58
    Likes Received:
    0
    Occupation:
    Web Developer
    Location:
    Best in the World
    Home Page:
    send sample i will help u
     
  4. motron

    motron Registered Member

    Joined:
    Apr 6, 2010
    Messages:
    93
    Likes Received:
    25
    If I understand your question - you are trying to set the thumbnail and featured image with different pictures.....
    you can specify the post image/thumbnail with the following customer field code; post_image. The value will be the link to the picture you want to use as thumbnail.
     
  5. 10zen

    10zen Regular Member

    Joined:
    Feb 26, 2010
    Messages:
    428
    Likes Received:
    194
    Occupation:
    IM Entrepreneur
    Location:
    World with Infinite Possibilities
    Thanks for trying to help but I know that already.

    I don't want to keep adding featured image separately, instead want to assign first post image as
    post thumbnail.

    Used this code:
    Code:
    function auto_featured_image() {
        global $post;
    
        if (!has_post_thumbnail($post->ID)) {
            $attached_image = get_children( "post_parent=$post->ID&post_type=attachment&post_mime_type=image&numberposts=1" );
            
          if ($attached_image) {
                  foreach ($attached_image as $attachment_id => $attachment) {
                       set_post_thumbnail($post->ID, $attachment_id);
                  }
             }
        }
    }
    // Use it temporary to generate all featured images
    add_action('the_post', 'auto_featured_image');
    // Used for new posts
    add_action('save_post', 'auto_featured_image');
    add_action('draft_to_publish', 'auto_featured_image');
    add_action('new_to_publish', 'auto_featured_image');
    add_action('pending_to_publish', 'auto_featured_image');
    add_action('future_to_publish', 'auto_featured_image');
    
    But this exact code is already in themes's function.php but don't know how to
    turn it on. But if I add this code it works but with mentioned glitch.
     
  6. 10zen

    10zen Regular Member

    Joined:
    Feb 26, 2010
    Messages:
    428
    Likes Received:
    194
    Occupation:
    IM Entrepreneur
    Location:
    World with Infinite Possibilities
    If you mean theme then here's the link:
    Code:
    http://www10.zippyshare.com/v/58768260/file.html