Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1024

    Hello!

    Great template!

    One problem I don’t know how to resolve:

    I have a blog with more than 4000 posts, and I’ve customized your theme for it’s new design. http://www.kmkz.ro/

    The problem is, all my posts have “attachment” images and don’t have Post Thumbnail or Featured image set in the WP admin.

    I have to ask you to help me with modifying the home and archive/category pages so it can display the post’s first attachment image in it’s content if there is no “preview image”. Another solution would be to give me some kind of an advice on how to recreate the thumbnails for my older posts.

    The current solution I have is like this:

    $preview_image = kriesi_post_thumb($post->ID, array('size'=> array('M'),

    'display_link' => '_prev_image_link',

    'linkurl' => array ('L','_preview_big'),

    'wh' => $k_option

    ));

    if ($preview_image == "") {

    $attachments = get_children( array(

    'post_parent' => get_the_ID(),

    'post_type' => 'attachment',

    'numberposts' => 1, // show all -1

    'post_status' => 'inherit',

    'post_mime_type' => 'image',

    'order' => 'ASC',

    'orderby' => 'menu_order ASC'

    ) );

    foreach ( $attachments as $attachment_id => $attachment ) {

    $src = wp_get_attachment_image_src( $attachment_id, array(150, 150) );

    $preview_image = '';

    The above solution needs one more thing, to have a default image if the image can be shown or is not found.

    I need a solution guys. Fast!

    Thanks,

    #33678

    Hey,

    WordPress 2.9 introduced the post thumbnail / featured post functionality and removed the requirement for resizing scripts such as timthumb to display images at the correct size. The bad news here is that images are resized when uploaded according to the specified sizes in the theme functions.php file so any images uploaded earlier would need to be re-uploaded to use WP’s resized.

    I have found a script for you to get the first image from each post and display this as the featured image – you can view the details here: http://www.wprecipes.com/how-to-get-the-first-image-from-the-post-and-display-it

    After adding the function to your functions.php file, you would need to update this code:

    if($preview_image) {
    echo '<div class="entry-previewimage rounded preloading_background">';
    echo $preview_image;
    echo '</div>';
    }

    to this:

    if($preview_image) {
    echo '<div class="entry-previewimage rounded preloading_background">';
    echo $preview_image;
    echo '</div>';
    } else {
    echo catch_that_image();
    }

    I hope this helps you in the right direction :)

    James

    #33679

    Hello James,

    Thank you for your help, but as I told you I would need like 3 IF-es to get this thing working as it should be:

    1. If there is a post thumbnail -> display it.

    2. If there is no post thumbnail -> use your suggestion catch_that_image();

    3. If there is no image in the post -> display category image or some other image I define somewhere.

    Is this doable?

    Thanks,

    Gergo

    #33680

    Just save the result of catch_that_image(); into a variable and check the content again. So i.e.

    if($preview_image) {
    echo '<div class="entry-previewimage rounded preloading_background">';
    echo $preview_image;
    echo '</div>';
    } else {
    $preview_image = echo catch_that_image();
    if($preview_image == "") {
    $preview_image = "http://my-default-image.png";
    }
    }

    echo $preview_image;

    The Dude

    #33681

    Hello,

    Thank you for your suggestions.

    I have question about this image replacement solution. Is there a way to get the “Medium” sized images for the catch_that_image(); function?

    Can the kriesi_post_thumb be used if there is no post thumbnail to display the first image from the articles?

    As I know, timthumb is used for the kriesi_post_thumb function. Can I use this function and change the “source” of the image to the one grabbed from the post content?

    THanks.

    #33682

    Hey,

    1.) The Catch That Image function grabs the first post image so it’s size is dictated by the size of the first image.

    2.) No, you need to re-write the kriesi_post_thumb function to achieve this which would be overwritten when a never version of the theme was released (generally you shouldn’t touch anything in the /framework folder unless you really have to).

    3.) Sure, you’d still need the catch_that_image function to grab the image and remember that the maximum image size you set for timthumb (to avoid pixellation / scaling) would be the size of the smallest image in your 4000+ posts.

    Your alternative is to go through each post and manually add a featured image. This would take a while though…

    James

Viewing 6 posts - 1 through 6 (of 6 total)

The topic ‘Featured image vs post thumbnail vs first image in post. URGENT help needed!’ is closed to new replies.