• Resolved Damien

    (@takster)


    Hi.

    I’m trying to use a custom field image in my single.php and index, but I dont know how to make wordpress take out the comma , in between images when it goes to post them.

    Example, I have a custom image field called “images” with the following:

    https://localhost.com/wp-content/uploads/classipress/hi-yall-1.jpg,https://localhost.com/wp-content/uploads/classipress/hi-yall-2.jpg

    and I can show the first image uploaded in single.php with my loop the way I like it:

    <?php $postimageurl = get_post_meta($post->ID, 'images', true); ?>
    <p><img src="<?php bloginfo('template_directory'); ?>/timthumb.php?src=<?php echo get_post_meta($post->ID, "images", true); ?>&w=600&zc=0" alt="" /></p>

    if I have more then one image the comma gets placed in the image link and screws it all up.

    Same with index.php, if I use more then one image, it inserts the comma and screws the img src url. here is my index page image grab code.

    <?php $postimageurl = get_post_meta($post->ID, 'images', true); ?>
    <div class="thumb">
    <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
    <img src="<?php bloginfo('template_directory'); ?>/timthumb.php?src=<?php echo get_post_meta($post->ID, "images", true); ?>
    &w=300&zc=1" alt="" border="0" /></a>

    What would I need to add/do to both my single/index code blocks above, so I can separate the images and not have the comma screw up the img src url when I have more then one image in the custom field?

    thanks for any help.
    / end rant

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Damien

    (@takster)

    single.php resolved, i used

    <?php
    $images = get_post_meta($post->ID, 'images', true);
    //check that we have a custom field
    if ($images != "")
    {
    // Separate our comma separated list into an array
    $images = explode(",", $images);
    //loop through our new array
    foreach ($images as $image)
    {
    echo "<img src='https://localhost.com/wp-content/themes/classipress/timthumb.php?src=" . $image . "&w=600&zc=0' alt='' />";
            }
          }
    ?>

    however my above index.php code does not understand how to grab only the first image, and drop the comma between any extra uploaded images and only show the first uploded image.

    At the moment I get

    <a href="https://localhost.com/2009/12/hi-yall/" title="hi yall’">
    <img src="https://localhost.com/wp-content/themes/press/timthumb.php?src=https://localhost.com/wp-content/uploads/press/hi-yall-7879.jpg,https://localhost.com/wp-content/uploads/press/hi-yall-7879.jpg&w=300&zc=1" alt="" border="0" /></a>

    I need:

    <a href="https://localhost.com/2009/12/hi-yall/" title="hi yall’">
    <img src="https://localhost.com/wp-content/themes/press/timthumb.php?src=https://localhost.com/wp-content/uploads/press/hi-yall-7879.jpg&w=300&zc=1" alt="" border="0" /></a>
    Thread Starter Damien

    (@takster)

    fixed it ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘need help using timbthumb, custom fields and comma separated images’ is closed to new replies.