Display an image from a pods generated field

The Pods Framework has been growing in leaps and bounds and there are a bunch of new “developer toys” in the framework that are not fully documented yet but are super awesome (yea, that’s a technical term).

pods_image() : outputs the <img src=””/> of an image file that was uploaded via a pods file upload field.

How to use it:

That’s literally all you need here! You can define the sizes based on the sizes that you have registered in your theme.

The default image sizes are ‘thumbnail’, ‘medium’, ‘large’, and ‘full’.

Alternatively, you can use pods_image_url() if you did not want the whole <img> tag and just wanted the plain path to the image. This is useful if you wanted to use the image as a background or some other non-typical use.

If you wanted to add new image sizes, check out this post in the WordPress Codex.

 

The_Idiot

About Lindsay

Self made millionaire.. Oops I mean web developer.. who started out learning how to build websites with tables and dreamweaver, I now almost entirely focus on CMS-based development, usually WordPress. I love coding and designing and regularly switch between my left and right brains.

11 thoughts on “Display an image from a pods generated field

  1. igloobob

    Hello Lindsay,

    Struggling with this, I can’t get it working and am clearly doing it wrong being a novice!

    Any chance you could please point me in the right direction of how I edit this code to use this selecting custom image size method?

    Any help much appreciated!!

     

    • Lindsay

      Can you tell me what the result of the above code is? Do you get an error or nothing at all?

  2. igloobob

    Hi Lindsay,

    that code above is the working code that just pulls the  default image, this is the code I ended up with after your previous help got it all working. So really what I’m not sure about is how to edit this working code to include the specific custom image size I have (new-size). I tried editing this line below to reflect what you had above, changing the field name and the size to my new custom size name but that ended up with no image showing at all.

    I ended up with this:

    It just stopped rendering anything on the page after the first project title. Clearly I’ve done it completely wrong which isn’t surprising ha!

     

     

    • Lindsay

      This part:
      echo $pic; ?>" alt=" Project" />
      Is all wrong.

      echo $pic;    is all you need to output an image, period. Just add that and you will see.

  3. igloobob

    So I enter this:

     

    And it gives me fatal error:

    Fatal error: Call to a member function field() on a non-object in /data02/c2626348/public_html/dev/wp-content/themes/pndaly/pods_template.php on line 65

    Sorry for being a complete numpty here and thanks again for your help – web design for idiots is certainly true in this case!

  4. igloobob

    Hi Lindsay, by the way would these be better done as private email communication by donation so I’m not clogging up your comments with my problems??

  5. Lindsay

    ^ Do this. You had your variables mixed up. You had $project_image as the variable that stored the image information but then in the pods_image() function you are trying to use $pic[ID] which you don’t have defined as your image variable.  You then strangely set $pic as some unknown $featured variable which doesn’t exist.

    I might recommend you spend a little more time learning PHP before delving into something this “complex” for a beginner. There are websites like http://www.codecademy.com/ which can help

  6. igloobob

    Hi Lindsay,

    hmm, that new code gives me another error.

    Fatal error: Call to a member function field() on a non-object in/data02/c2626348/public_html/dev/wp-content/themes/pndaly/projects_pods_template.phpon line 63

    I’m just going to use the working code and upload images the correct size for now rather than specifying a custom image size and take your advice and get learning!

     

     

    Thanks for the help!

    • Lindsay

      FYI – I finally got the subscription thing worked out.

  7. Lindsay

    OOPS I just saw this! I just noticed the issue.

    $pic = $featured->field('project_image');

    Should be
    $pic = $mypod->field('project_image');

    The code above is kind of messy and it probably should be cleaned up a bit, but try that out. If it returns an error, let me know which line it is in the code you paste because the line number in the error is not going to match the line number you paste since you are not pasting the ENTIRE page.

  8. Hi Lindsay,

    I left a message on your other website but I just thought I’d try you here too.

    I thought the whole thing about pods was not having to deal with PHP but using Pods templates to control the front end display. If you’re available for hire to help me with this, please contact me. Thanks,

    Todd

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">