WordPress.org

Ready to get started?Download WordPress

Forums

Automatic Featured Image Posts
[resolved] Ability to have the featured image not the fullsize uploaded image (6 posts)

  1. DavidGMiles
    Member
    Posted 1 year ago #

    My scenario is as follows – use your plugin to hook into every image that is uploaded and create a post from that, which is exactly what you intended, all good so far, use your afip_new_post_content to add in some post content as per below:

    <?php
    /*
    Plugin Name: Add Post Content to Automatic Featured Image Posts
    Plugin URI:
    Description:
    Version:
    Author:
    Author URI:
    License:
    License URI:
    */
    add_filter( 'afip_new_post_content', 'dgm_change_afip_post_content', 10, 2 );

    /* Grabs the image source for the newly created image and inserts it
    * into the new post content along with a one line paragraph. */

    function dgm_change_afip_post_content( $post_content, $attachment_id ) {

    $image_title = get_the_title($attachment_id);
    $image_caption = $attachment->post_excerpt;
    $image_description = $image->post_content;
    $image_attributes = wp_get_attachment_image_src($attachment_id, $size);
    $image_full_attributes = wp_get_attachment_image_src($attachment_id, 'full');

    $attachment = get_post($attachment_id);
    $content = $attachment->post_content;
    $content = apply_filters('the_content', $content);
    $image_description = str_replace(']]>', ']]>', $content);

    $attachmenturl = wp_get_attachment_url($attachment_id);
    $attachmentimage = '<img src="' . $image_attributes[0] . '" alt="' . $image_title . '" />';

    $attachment_page = get_attachment_link($attachment_id);
    $attachment_page_link = 'Full Image Details';

    $post_content = '<p>' . $image_description . '</p><!--more-->' . '' . $attachmentimage . '' . $image_title . ' | ' . $attachment_page_link;

    return $post_content;

    }

    This all works fine – so I figured everything was good – until I realised my homepage, which makes heavy use of the featured images was turning slow and starting to run like a dog, then I realised, my 1024 * 768 images are being used on the home page as the featured image and scaled in the browser – so this making my home page hurt a lot

    Now I assume you do your magic in the create_post_from_image function – what I really need to do here – and it may benefit others, is to not add the full-size image to the new post as the featured image, but instead one of my smaller image sizes – so my homepage doesn’t hurt as much – I hope that I have explained this well enough

    Looking at the create_post_from_image I cannot for the life of me work out how to change the size of image assigned to the featured image of the new post – can you give me a pointer at all here?

    http://wordpress.org/extend/plugins/automatic-featured-image-posts/

  2. ntracer
    Member
    Posted 1 year ago #

    Hello! Can u help me with this plugin?
    I want creates a new post with a full size image, everytime I uploaded it!

  3. Jeremy Felt
    Member
    Plugin Author

    Posted 1 year ago #

    @DavidGMiles - I can't tell for sure, but it sounds like your theme is not making use of actual post thumbnails. The code you give as an example is taking the full image source and inserting it directly into the content.

    If your theme supports Post Thumbnails via code like add_theme_support( 'post-thumbnails' ), it should generate various size images for you based on code like this - add_image_size( 'some-description', 640, 480 ) and display these on the front end via code like the_post_thumbnail( 'some-description' ). If you are using <img src="..." /> instead of the_post_thumbnail(), then you may not be getting the expected results with this plugin.

    @ntracer - Please create another topic with full details on your issue.

  4. DavidGMiles
    Member
    Posted 1 year ago #

    Ive tried a few themes - all of which are supporting the post-thumbnail functionality - there is a whole lot of code that runs to resize a featured image to a thumbnail if you upload it from the admin area - before attaching it to a post - this plugin as far as I can see just takes the uploaded image and attaches that to the post without resizing it to the post-thumbnail size - am I wrong on that score? Therefore when WP asks for the thumbnail, it expects it to have been resized during the upload operation, since it has not, it just takes what it is given - the fullsize image

  5. DavidGMiles
    Member
    Posted 1 year ago #

    I'd have thought the plugin should be attaching the thumbnail id after http://codex.wordpress.org/Function_Reference/wp_generate_attachment_metadata ran

  6. Jeremy Felt
    Member
    Plugin Author

    Posted 11 months ago #

    The plugin assigns the image as a featured image to the new post. At the time of upload it is a full size image, but themes that make use of post thumbnails/featured images will display the proper size. Inserting the URL directly into the content at the time of upload will not achieve the same effect. There may be a hook a bit later in the process when WordPress has generated the new sizes that could be used to help find a URL for the content, but I'm not sure if that can be used during the plugin's portion of things.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic