• 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

Viewing 1 replies (of 1 total)
  • Thread Starter Yukon Cornelius

    (@jimmmy)

    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=”https://www.mysite/wp-content/themes/mytheme/scripts/timthumb.php?w=233&h=157&zc=1&src=%s&#8221; 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: https://aan.dudut.com/blog/utilizing-timthumb-in-wordpress-templates/

Viewing 1 replies (of 1 total)
  • The topic ‘How to add timthumb to featured post slider’ is closed to new replies.