Forums

How to Custom Field show image/thumbnail (5 posts)

  1. sqlbytemladen
    Member
    Posted 3 years ago #

    Hi,
    i have a magazine style theme that i want to show images/thumbnails on front page, my site is at http://hithottech.com
    But the problem is that i don't know to show image via custom fields, i tried a lot of things but didn't manage to do it.
    So if someone know the way how to do it, via some plugin or something please help me because this is really annoying to me.
    P.S. I tried that timthumb plugin but i can't manage to get it work on my host.

  2. Michael Fields
    Theme Wrangler
    Posted 3 years ago #

    Please see this thread for an IMHO better solution to this kinda thing: http://wordpress.org/support/topic/209656?replies=11

    Note: try the second bit of code that I posted.

    If this is not to your liking, you could try the following steps:

    First create a directory in your WordPress install directory and put your thumbnail images there. Upload these to your server.

    Next come up with a "slug" to use for your image file name. Something like "homepage_thumbnail_filename" would work well.

    Next, add a custom field to a post choose "homepage_thumbnail_filename" for the key and type in the name of one of the files in that directory we created in step one. use full name with extension: 'taco_pudding.jpg'

    Open the theme file that displays your homepage and type in the following code into your loop:

    $img_filename = get_post_meta( $post->ID, 'homepage_thumbnail_filename' , true );
    $path_to_img = get_bloginfo( 'url' ) . '/custom_thumbnail_directory/' . $img_filename;
    $custom_thumb_img = '<img src="' . $path_to_img . '" alt="" />';
    print $custom_thumb_img;

    This should work. Let me know what happened...

  3. sqlbytemladen
    Member
    Posted 3 years ago #

    mfields your the man ! :) I used the link you provided on other thread.
    It displays image that i state in custom field, can you please just tell me what part should in your code so that it displays images from custom field with name image2 because image is already used for that timthumb plugin.

    Again thanks, you helped me a lot.

  4. sqlbytemladen
    Member
    Posted 3 years ago #

    This is the code from the mentioned timthumb plugin:
    <?php if ( get_post_meta($post->ID,'image', true) ) { ?>
    And this is yours:

    <?php
    $images = get_children(
    array(
    	'post_parent' => $post->ID,
    	'post_status' => 'inherit',
    	'post_type' => 'attachment',
    	'post_mime_type' => 'image',
    	'order' => 'ASC',
    	'orderby' => 'menu_order'
    	)
    );
    
    if ( $images ) {
    $count = 1;
    foreach ( $images as $id => $image ) {
    	if( $count === 1 ) {
    		$img = wp_get_attachment_thumb_url( $image->ID );
    		$link = get_permalink( $post->ID );
    		print "\n\n" . '<div><a href="' . $link . '"><img src="' . $img . '" alt="" /></div>';
    	}
    	$count++;
    }
    }
    ?>

    If i delete that timthumb code, it gaves me an error, and if i change image to image2 it doesn't work.
    But if i leave everything like it is, it try to display image from timthumb (give broken image), and then display image.
    So.. i don't know how to fix it :|

  5. Michael Fields
    Theme Wrangler
    Posted 3 years ago #

    hmmm... think i need some more infoemation. could you please post all of the code in the file to pastebin and then post a link to the pastebin here? Thanks!

    http://wordpress.pastebin.com/

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.