[Closed] wpv-post-featured-image as a link

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

This topic contains 7 replies, has 4 voices.

Last updated by Mario 7 years ago.

Assigned support staff: Mario.

Author
Posts
#9317

I would like to make the wpv-post-featured-image a link to itself.

I used [wpv-post-featured-image] which puts the tag into my template and works fine but when I do <a href="[wpv-post-featured-image]">[wpv-post-featured-image]</a> it doesn't work because [wpv-post-featured-image] generates the whole image tag, not just the URL. I looked through the documentation but didn't see if there is a way to do this?

#9337

Hi Chris,

We don't have it implemented as returning URL only (it's how WordPress core works for now). You can use Types image instead if you need more image features.

Best,
Mario

#17115

How do you use Types image to access the featured post image? What is the correct format?

Much appreciated.

#19954

I need this as well, what is "Types Image"?

#20146

I still have had no luck getting this to work. If I ever find a way, I will update you guys. My personal site has been on hold for months. This plugin is EXACTLY what I want to use but its too complicated to use! I can't get a simple portfolio setup to work!!! VERY frustrating!!

#20194

Ther best way you can do this, is to create your own short code to get the url of the featured image of the current post.

Here's how:

1) Create a function that will return the url
2) Register a shortcode that will call the function you created
3) Use that shortcode in your Views template

Here goes:

First open up your themes functions.php file, (or create your own short codes plug-in, or similar)
In your functions.php (or plug-in), add this to the file:

/** ***************************************************
 * get image src for featured image of post (large version)
 */


## Register our short code at the appropriate time during the WordPress Boot process. ##
add_action( 'init', 'wpk_register_shortcodes');

function wpk_register_shortcodes(){
   add_shortcode('my_get_thumbsrc', 'my_get_thumbsrc');
}


 ## Function to return the source url for the featured image of a post ##
function my_get_thumbsrc($id) {
   global $post;

   ## Here we check if an ID was specified, if not, we use the ID of the current post
   $id = ($id) ? $id : $post->ID;


   if ( has_post_thumbnail($id)) {

      ## We're getting the url of the large version of the image here, options are 'thumbnail', 'medium', 'large' or 'full' ##
      $image_url = wp_get_attachment_image_src( get_post_thumbnail_id($id), 'large');

      ##  $image_url is an array; It holds url, width and height. See wp_get_attachment_image_src at the WP codex##
      return $image_url[0]; // return just the url

  }

}

Now we have a new shortcode available for use. Its called 'my_get_thumbsrc'

The next thing is to use it in the Views template like this:

<a href="[my_get_thumbsrc]">[wpv-post-featured-image size="medium"]</a>

The above will display the featured image at medium size, and link it to it's large size version.
If you use a lightbox plugin, you can add the appropriate lightbox tag as well:

<a href="[my_get_thumbsrc]" rel="lightbox[post-[wpv-post-id]]">[wpv-post-featured-image size="medium"]</a>
#20195

@mario I'm still not sure what you mean by "Use Types image instead" .. what's that?

#20243

@mikkel, instead of setting featured image, you can add a custom field group with an Image field. It has a number of options (size including) and could be used with or without a URL.

The topic ‘[Closed] wpv-post-featured-image as a link’ is closed to new replies.