WordPress.org

Ready to get started?Download WordPress

Forums

Simple Fields
[resolved] How to display a sized image from Simple Fields repeatable field (3 posts)

  1. robalan
    Member
    Posted 9 months ago #

    I am having the hardest time creating a slideshow from a repeatable field group. I've tried piecing everything that I could find from the documentation and from others who have had similar issues, but everything I try results in an "invalid argument" or no image src returned.

    This code is working, but I need to know how to tell it to display the 'large' size image:

    <ul class="slides">
        <?php
            $slideshow_repeat = simple_fields_get_post_group_values(get_the_id(),"Slideshow", true, 2);
                foreach ( $slideshow_repeat as $slide ) {
                    $image_src = wp_get_attachment_image_src($slide['Slide']);
        ?>
        <li>
            <img src="<?php echo $image_src[0]; ?>" alt="<?php echo $slide['Title']; ?>"/>
            <h2><?php echo $slide['Title']; ?></h2>
            <p><?php echo $slide['Caption']; ?></p>
            <p><?php echo $slide['Image Credit']; ?></p>
        </li>
    
        <?php
            }
        ?>
    </ul>

    If anyone can help, I'd really appreciate it.

    http://wordpress.org/plugins/simple-fields/

  2. robalan
    Member
    Posted 9 months ago #

    Fixed. Here's what worked:

    <ul class="slides">
        <?php
        $slideshow_repeat = simple_fields_get_post_group_values( get_the_id(), "Slideshow", true, 2 );
        print_r( $slideshow_repeat );
        foreach ( $slideshow_repeat as $slide ) {
            // This is the important bit
            $image_src = wp_get_attachment_image_src( $slide['Slide'], 'full' );
            ?>
            <li>
                <img src="<?php echo $image_src[0]; ?>" alt="<?php echo $slide['Title']; ?>"/>
                <h2><?php echo $slide['Title']; ?></h2>
                <p><?php echo $slide['Caption']; ?></p>
                <p><?php echo $slide['Image Credit']; ?></p>
            </li>
    
            <?php
        } ?>
    </ul>

    $slide['Slide'] was returning the attachment ID, so we didn't need to go any deeper in the array to assign the size. Hope that makes sense!

  3. robalan
    Member
    Posted 9 months ago #

    Marking as resolved.

Reply

You must log in to post.

About this Plugin

About this Topic

Tags