Forums

Pods CMS Framework
[resolved] Trouble looping bi-directional images+data in Pods CMS (2 posts)

  1. rbrt
    Member
    Posted 1 year ago #

    Hi there!

    I'm building a record label website and I'm stuck in a loop error. Hopefully someone can help me out with this. I am losing my mind.

    In a pod ("artists") I want to pull all one artist's albums from another pod ("releases") through the bi-directional field ("releases_conn").
    Everything works out fine except the images ("releases_img") shows up in the wrong order in the for loop.

    Code:

    if (is_array($release_conn)) {
    echo '<h3>Releases</h3>';
    echo '<ul>';
    for ($i=0; $i<count($release_conn); $i++)
    {
        $rl = $release_conn[$i];
        // Check if compilation (various artists)
        if ($rl['compilation'] == 1) { $release_title = $rl['name']." (Various Artists)"; } else { $release_title = $rl['name']; }
    
        $thumb = $artists->get_field('release_conn.releases_img');
        $thumb = $thumb[$i];
        // Get thumbnail image size
        $size = 'thumbnail';
        if(!empty($thumb)) {
        $attachment_id = $thumb['ID'];
        $sized = image_downsize($attachment_id,$size);
    
        echo '<li>';
        if(is_array($sized)) {
        echo '<a href="releases/'.$rl[slug].'/"><img src="'.$sized[0].'" alt="'.$release_title.'"></a><br />'; }
        }
        echo '<p><a title="'.$release_title.'" href="releases/'.$rl[slug].'/">'.$release_title.'</a><br />'.$rl['releases_format'].' ('.date("Y", strtotime($rl['releases_releasedate'])).')</p></li>';
    
    }
    echo '</ul>';
    }

    The images shows up in a different order than the other info. I guess it's not correct to pull this inside the for loop as :

    $thumb = $artists->get_field('release_conn.releases_img');
    $thumb = $thumb[$i];

    But I don't know what else to do.
    I need to connect the image files [guid] to the correct pod item (ID).
    Please help!

    Thanks!

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

  2. Scott Kingsley Clark
    Member
    Posted 1 year ago #

    You can use the second field in get_field to order by a specific id, but I recommend using while($artists->fetchRecord()) to loop through the data, and pull in the release_conn Pod as it's own loop instead of using $release_conn - then you could ensure everything is connected correctly and ordered in the way you'd like.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic