WordPress.org

Ready to get started?Download WordPress

Forums

Adding image size to an image hack (1 post)

  1. Avraham
    Member
    Posted 3 years ago #

    Hi
    I've been trying all morning to add the image sizes to an <img> tag.
    I've been using for a while this hack fond here: http://www.wprecipes.com/how-to-get-the-first-image-from-the-post-and-display-it it's been working great for me. But now i am trying to add the width and height to the HTML so jQuery can use it for some other code. Does anyone have an idea why this isn't working?
    Thanks a lot!

    This code is on my functions.php page:

    /* thumbnails on archive pages */
    function the_thumb($size = "medium", $add = "") {
    	global $wpdb, $post;
    	$thumb = $wpdb->get_row("SELECT ID, post_title FROM {$wpdb->posts} WHERE post_parent = {$post->ID} AND post_mime_type LIKE 'image%' ORDER BY menu_order");
    
    	list($w, $h, $type) = getimagesize($thumb);
    
    	if(!empty($thumb)) {
    		$image = image_downsize($thumb->ID, $size);
    		print "<img src='{$image[0]}' alt='{$thumb->post_title}' height='{$h}' {$add} />";
    	}
    }

    and this code is ion the theme page - index.php:

    <?php echo the_thumb('thumbnail', 'class="alignleft"'); ?>

Topic Closed

This topic has been closed to new replies.

About this Topic