Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

i'm trying to set up a mobile theme for my wordpress site. My desktop version uses themejunkie's weekly theme and my mobile version uses dotmobi theme.

the Dotmobi theme pulls out the first image and displays as a thumbnail where as the weekly theme displays the 'featured image' as a thumbnail or a picture that is defined in a custom field value 'thumb'

How can I make use of this same logic for dotmobi as well?

I tried get_thumbnail() but that doesn't work. Any help on this please.

I also tried by putting this code into my functions.php

// Get image attachment (sizes: thumbnail, medium, full)
function get_thumbnail($postid=0, $size='full') {
    if ($postid<1) 
    $postid = get_the_ID();
    $thumb_key = get_theme_mod('thumb_key');
    if($thumb_key)
        $thumb_key = $thumb_key;
    else
        $thumb_key = 'thumb';
    $thumb = get_post_meta($postid, $thumb_key, TRUE); // Declare the custom field for the image
    if ($thumb != null or $thumb != '') {
        return $thumb; 
    } elseif ($images = get_children(array(
        'post_parent' => $postid,
        'post_type' => 'attachment',
        'numberposts' => '1',
        'post_mime_type' => 'image', ))) {
        foreach($images as $image) {
            $thumbnail=wp_get_attachment_image_src($image->ID, $size);
            return $thumbnail[0]; 
        }
    } else {
        return get_bloginfo ( 'stylesheet_directory' ).'/images/default_thumb.gif';
    }

}

and called the same in my index.php through

<?php echo '<a href="'.get_permalink($post->ID).'" rel="bookmark"><img src="'.get_bloginfo('template_url').'/timthumb.php?src='.get_thumbnail($post->ID, 'full').'&amp;h='.$height.'&amp;w='.$width.'&amp;zc=1" alt="'.get_the_title().'" /></a>' ?>

For some odd reason the thumbnails aren't displaying

share|improve this question
    
Well now using firebug if I check the thumbnail URL it's the same as my desktop theme, but somehow the image won't load. If I copy paste the same URL from the desktop theme back to the mobile them (using firebug) the thumbnail is displayed. –  Sledge81 May 16 '11 at 17:55
    
Looking around for timthumb issues I checked to see if the file permissions were correct. both timthumb and cache are set to 755. from my ftp client I see files are being generated in cache, but the main index.php file doesn't display any thumbnails. –  Sledge81 May 16 '11 at 18:01
add comment

1 Answer

up vote 0 down vote accepted

Try this code.

Then temporarily set permissions to the cache folder to 774 and the timthumb.php file to 750, you can increase or decrease the permissions as you see fit (or aslong as it stops working, then it'll be time to loosen up the permissions).

<?php
    // If there are images get them
    if ( $images = get_children(array(
        'post_type' => 'attachment',
        'numberposts' => 1,
        'post_status' => null,
        'post_parent' => $post->ID
    )));

    foreach( $images as $image ) {
         $attachment = wp_get_attachment_image_src( $image->ID );

    // Variables for timthumb
    $width = 160;
    $height = 160;
    $zoom_crop = 1;
?>

<a href="<?php the_permalink() ?>" rel="bookmark" title="<?php esc_attr( printf( __( 'Click to read %s', 'truereps' ), get_the_title() ) ); ?>">
<img src="<?php bloginfo( 'template_directory' ); ?>/inc/scripts/timthumb.php?src=<?php echo $attachment[0]; ?>&amp;w=<?php echo $width; ?>&amp;h=<?php echo $height; ?>&amp;zc=<?php echo $zoom_crop; ?>" alt="<?php the_title(); ?>" />
</a>

<?php } ?>
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.