• I have a slider in my theme running, it basically pulls Featured Images. I would like to be able to add a custom URL to each Featured Image via a Custom Fields that I have created called “slide_url”. Anyone has an idea how to make this work? Thanks!

    This is my code in Functions.php:

    <?php function get_custom_field_value($szKey, $bPrint = false) {
    	global $post;
    	$szValue = get_post_meta($post->ID, $szKey, true);
    	if ( $bPrint == false ) return $szValue; else echo $szValue;
    }
    ?>

    This is my modified code which is not working at the moment:

    [Code moderated as per the Forum Rules. Please use the pastebin]

Viewing 1 replies (of 1 total)
  • <?php
    $values = get_post_custom_values('slide_url');
    if (isset($values[0])) {
        echo '<a href="'.get_permalink().'" ><img src="'.$values[0].'" alt="'.get_the_title().'" /></a>';
    } elseif ( has_post_thumbnail() ) {
       $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large');
       echo '<a href="' . $large_image_url[0] . '" title="' . the_title_attribute('echo=0') . '" >';
       the_post_thumbnail('blogbig');
       echo '</a>';
     } ?>

    The featured image ‘blogbig’ in your slider has the link to the large image. In this example custom image has the link to the post url get_permalink(). To make it work as slider image you need second custom field image like ‘slide_url_large’ )))

Viewing 1 replies (of 1 total)
  • The topic ‘Add custom URL to Featured Image via Custom Fields’ is closed to new replies.