WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to add timthumb to featured post slider (2 posts)

  1. Yukon Cornelius
    Member
    Posted 3 years ago #

    Hi,
    I'm using the following code for a jquery slider that pulls images from posts within a given category. It works fine, but I'd like to add the timthumb script to save having to resize each image.

    I have timthumb set up correctly in a scripts directory, but I am struggling to add the extra code to the slider code so that the script applies to the images that are generated.

    Can anyone point me in the right direction?

    <ul id="carousel">
                <?php
                $featured_posts = get_posts('numberposts=7&category=$cat');  
    
                foreach( $featured_posts as $post ) {
                   $custom_image = get_post_custom_values('featured_image', $post->ID);
                   $image = $custom_image[0] ? $custom_image[0] : get_bloginfo("template_directory")."/images/no-featured-image.jpg";
                   printf('<li><a href="%s"title=""><h2 class="slidrpostheading">%s</h2><img src="%s" alt="%s" /></a></li>', get_permalink($post->ID), $post->post_title, $image, $post->post_title);
                }
                ?>
        </ul>

    Thanks!

    Jimmmy

  2. Yukon Cornelius
    Member
    Posted 3 years ago #

    update...

    I figured it out!

    `<ul id="carousel">
    <?php
    $featured_posts = get_posts('numberposts=7&category=$cat');

    foreach( $featured_posts as $post ) {
    $custom_image = get_post_custom_values('thumb', $post->ID);
    $image = $custom_image[0] ? $custom_image[0] : get_bloginfo("template_directory")."/images/no-featured-image.jpg";
    printf('<li><a href="%s"title=""><h2 class="slidrpostheading">%s</h2><img src="http://www.mysite/wp-content/themes/mytheme/scripts/timthumb.php?w=233&h=157&zc=1&src=%s" alt="%s" /></a></li>', get_permalink($post->ID), $post->post_title, $image, $post->post_title);
    }
    ?>
    </ul>`
    I figured out you have to have an absolute path coz it's within the printf. I'm sure there is a much tidier way to do this, but it works at least.

    For anyone that's interested, here's a cool hack for timthumb: http://aan.dudut.com/blog/utilizing-timthumb-in-wordpress-templates/

Topic Closed

This topic has been closed to new replies.

About this Topic