PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Make an image a link in Post Template?

  1. UWEX
    Member

    When creating a post from a public-facing Gravity Form, I am able to insert an image of any size I want. However, I can't figure out how to make that image a link to the original size.

    Any ideas? I'm thinking I need to do something akin to:

    {Image:5:small:right} .. but have no idea how to get the '{something}' in the Template.

    Posted 12 years ago on Tuesday September 25, 2012 | Permalink
  2. You should be able to use a merge tag like this to get the url value: {Post Image:5:url}

    See this page of documentation:
    http://www.gravityhelp.com/documentation/page/Merge_Tags

    Posted 12 years ago on Tuesday September 25, 2012 | Permalink
  3. UWEX
    Member

    I got it working, but your example is just a tad off I think.

    {Image:5:url} still generates a full on Image tag, but if you include a SIZE before url..

    {Image:5:large:url} ... that gives you just the URL.

    However, I've now found another problem that I'm less optimistic that you can help me with. What I wanted to do was make the small Image a link to the big, by putting this in the Template:

    <a href='{Image:5:large:url}'>{Image:5:small}</a>

    The problem is that the field isn't required, and it generates some broken HTML if no image is uploaded. Is there any workaround to this? For example...
    {gf_if Image:5:large:url} :all my code: {/gf_if}

    Posted 12 years ago on Tuesday September 25, 2012 | Permalink
  4. Sorry about the example. Glad you were able to figure that out. We'll take a look at the documentation.

    Regarding your new issue, if the field is not required, and you add the HTML to your content template, it will result in broken HTML as you have discovered.

    The conditional shortcode does not work in the content template area. You may have to use your page or post template to conditionally include the HTML if there is a value in the field. Or you can use the gform_pre_submission_filter to change the postContentTemplate and make your merge tag conditional.

    Posted 12 years ago on Wednesday September 26, 2012 | Permalink
  5. UWEX
    Member

    > Or you can use the gform_pre_submission_filter to change the postContentTemplate and make your merge tag conditional.

    Is there any guidance on doing this? The gform_pre_submission page doesn't seem nearly verbose enough to really even hint at how to do this.

    Thanks

    Posted 12 years ago on Wednesday September 26, 2012 | Permalink
  6. Can you export your form please as XML (Forms > Import/Export > top menu item "Export Forms") and email it to me at chris@rocketgenius.com please? I will install it and take a look at your content template to see what needs to be made conditional and provide you some code to do that.

    Posted 12 years ago on Wednesday September 26, 2012 | Permalink
  7. Take a look at this code: http://pastebin.com/FwLbc09A This code will be added to your theme's functions.php. You will need to change the form ID on line 4, from 171 to your actual form ID.

    I took your content template and will use that when an image is uploaded. When no image is submitted with the form, since it's not a required field, an alternate content template will be used, with just {Details:2} in it. Let me know if you have any questions. I removed some blank lines. I was not sure if they were intentional for layout or not. You can add them back in if you need them.

    Posted 12 years ago on Thursday September 27, 2012 | Permalink
  8. UWEX
    Member

    This works perfectly. Thanks!!!

    Posted 12 years ago on Thursday September 27, 2012 | Permalink
  9. Thank you for the update.

    Posted 12 years ago on Thursday September 27, 2012 | Permalink

This topic has been resolved and has been closed to new replies.