• Resolved kmort

    (@kmort)


    Here’s the code I used to create my custom field.

    <span id="featured-image">
    <img src="<?php $values = get_post_custom_values("featuredpageimage");echo $values[0]; ?>"
    </span>

    Is there any way to make that image linkable?

    Thanks!

Viewing 13 replies - 1 through 13 (of 13 total)
  • Is values a valid URL?

    if so wrap it in an A tag
    <?php $values = get_post_custom_values(“featuredpageimage”);?>
    “>Underline me

    Thread Starter kmort

    (@kmort)

    Do you mean in the value field of the WP dashboard where I’ve created my page?

    I.e. use this in the featuredpageimage value field?

    etc.

    I’ve tried that — it doesn’t seem to work.

    Thread Starter kmort

    (@kmort)

    Do you mean in the value field of the WP dashboard where I’ve created my page?

    I.e. use an <a href, img src code in the featuredpageimage value field?

    I’ve tried that — it doesn’t seem to work.

    (sorry for the double post, wanted to be clear which code I was using)

    Thread Starter kmort

    (@kmort)

    In fact, I can’t even set my value to be a link. Is that a limitation of WP custom fields or have I mucked my code somewhere else, I wonder . . .

    I’m sorry, i screwed up the code above by not putting it in code tags. It was supposed to say

    Is values a valid URL?
    if so wrap it in an A tag

    <?php $values = get_post_custom_values("featuredpageimage"); ?>
    <a href="<?php echo $values; ?>">Underline me</a>

    If that does not work then please post the full content of what the “value” of a typical featuredpageimage custom field is.

    Thread Starter kmort

    (@kmort)

    The value for featuredpageimage is the url pointing to the image.

    Maybe my question isn’t clear.

    I can configure custom fields to point to images on my server — no problem with that.

    What I’d like is for the image, when it displays on my page, to serve as an image link to third site. Put another way, I want the featuredpageimage value to behave as if it were

    <a href="URL_OF_OTHER_SITE_HERE"><img src="URL_OF_MY_IMAGE_HERE"></a>

    I’ve tried using that code as the custom field value. Doesn’t seem to work.

    So use another custom field… something like this maybe?

    Somewhere inside the loop, but before the rest of the HTML (just to keep it out the way).

    <?php $myimage = get_post_meta($post->ID, 'field_one', true);?>
    <?php $myimagelink = get_post_meta($post->ID, 'field_two', true);?>

    Where “field_one and field_two” is actually the custom field names..

    Then wherever you want to display the image.

    <?php
    $the_image = '';
    
    if($myimagelink) :
      $the_image .= '<a href="'.$myimagelink.'">';
    
      if($myimage) :
        $the_image .= '<img src="'.$myimage.'" border="0" alt="'.$myimagelink.'" />';
      endif;
    
      $the_image .= '</a>';
    echo $the_image;
    endif;
    ?>

    Thread Starter kmort

    (@kmort)

    PERFECT!!!

    Thanks so much!!!
    xxxooo

    Oops that should actually be…

    <?php
    $the_image = '';
    if($myimagelink) : $the_image .= '<a href="'.$myimagelink.'">';
    
      if($myimage) : $the_image .= '<img src="'.$myimage.'" border="0" alt="'.$myimagelink.'" />';
      endif;
    
      $the_image .= '</a>';
    endif;
    echo $the_image;
    ?>

    The bottom 2 lines were the wrong way round.

    ??

    Thread Starter kmort

    (@kmort)

    Believe it or not it worked the first way too ??

    Thank You!!! I’ve looked everywhere for this snippet of code!!! You Rock t31os!!!!!!!! That was a productive 5 hours.

    Hi t31os,

    This is what I’ve been looking for. But I’d also like to track the links using onclick… is that possible?

    t31os, thanks so much! Is it possible to get a little more help with the code you provided please? I’m a total newbie at this. ??
    Where do you declare the URL? Do you need 2 custom field names: one for the image and one for the URL? Sorry, just a bit confused. Thanks again!

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘OK WP gurus! Possible to make custom field images linkable?’ is closed to new replies.