WordPress.org

Ready to get started?Download WordPress

Forums

Pods - Custom Content Types and Fields
[resolved] Calling specific image size (6 posts)

  1. Olly - OWMC
    Member
    Posted 1 year ago #

    Hello, i am using this code to call a list of pod items each with image fields:

    <?php
    $services = new Pod('services');
    $services->findRecords('id ASC', -1);
    $total_services = $services->getTotalRows();
    ?>
    <?php if( $total_services>0 ) : ?>
    <?php while ( $services->fetchRecord() ) : ?>
    <?php
    $services_id        = $services->get_field('id');
    $services_name      = $services->get_field('name');
    $services_photo     = $services->get_field('main_photo');
    $services_desc     = $services->get_field('description');
    $services_slug      = $services->get_field('permalink');
    $services_photo     = $services_photo[0]['guid'];
    ?>
    <div class="menubox2" style="background:url('<?php echo $services_photo; ?>')center;">

    Which works great. Until my client started uploading 3-4000px width images.

    So I wanted to know how I could make sure it only calls a specific size (thumb/medium/large/original).

    http://wordpress.org/extend/plugins/pods/

  2. Morklympious
    Member
    Posted 1 year ago #

    This might be helpful:

    http://codex.wordpress.org/Function_Reference/wp_get_attachment_image_src

    I'm unsure if your services is an extension of post, but I see that you have an ID, You could use the ID and then specify the size of the image that gets displayed with the second parameter of wp_get_attachment_image_src.

    Hope this helps!
    If not, then I hope you find a solution soon!

  3. Olly - OWMC
    Member
    Posted 1 year ago #

    thanks Mork, not sure how i can integrate wp_get_attachment_image into my code above. $services_photo is defined by the pod item field "main_photo".

    wordpress by default creates different sizes of all uploaded images and i wanted to take advantage of that. also have used smushit but don't think this is working either.

    l for now i'm just going to tell the client to upload smaller images.

  4. Scott Kingsley Clark
    Member
    Plugin Author

    Posted 1 year ago #

    Any images uploaded through Pods will be automatically resized by WordPress. So all you need to do is pass the file's ID into wp_get_attachment_image_src and that should work well.

    Or you can alternatively use our handy wrapper function and pass the file data, ID, or GUID into it:

    http://pods.io/docs/code/field-functions/pods-image/

  5. Olly - OWMC
    Member
    Posted 1 year ago #

    Thanks Scott, i will have to come back to this later in the week hopefully. Will update!

    By the way, new pods site looks slick! Waiting for the storm of work I have on to die down a bit before I get thoroughly into it.

  6. Olly - OWMC
    Member
    Posted 11 months ago #

    had a good chat with Phil Lewis.

    First off I've corrected my syntax so it is up to date. The syntax I originally posted here is out of date (http://pods.io/2012/08/30/differences-between-pods1-and-pods2/).

    In summary it now looks like this:

    <?php
    $services = pods('services');
    $services->find('id ASC', -1);
    $total_services = $services->getTotalRows();
    ?>
    <?php if( $total_services>0 ) : ?>
    <?php while ( $services->fetch() ) : ?>
    <?php
    $services_id        = $services->field('id');
    $services_name      = $services->field('name');
    $services_photo     = $services->field('main_photo');
    $services_slug      = $services->field('permalink');
    $services_photo     = pods_image_url ( $services_photo, $size = 'medium', $default = 0, $force = false );
    ?>

    Where "medium" could also be set to thumbnail, original, large...

    Basically I have learnt a bit about php. I was trying to implement pods_image_url but i was trying to use it as a "method", like so:
    $album_photo = $album->pods_image_url ( $album_photo, $size = 'medium', $default = 0, $force = false );

    Whereas I should have been using it as a "global function":
    $album_photo = pods_image_url ( $album_photo, $size = 'medium', $default = 0, $force = false );

    Ah the endorphins running around my brain...

    :)

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic