Created
October 9, 2019 11:33
-
-
Save stefanRepac/8b977ce065fcef688c217f85c90472eb to your computer and use it in GitHub Desktop.
ACF repeater - Get content by row
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $rows = get_field('sidebar_commercials', 'option' ); // get all the rows | |
| // $rand_row = $rows[ array_rand( $rows ) ]; // get a random row | |
| $row_count = count(get_field('sidebar_commercials', 'option')); // Count | |
| if( $the_query->current_post === 2 ) { | |
| if ($row_count >= 1) { | |
| $first_baner = $rows[0]; | |
| $baner_image_first = $first_baner['widget_commercial_image' ]; // get the sub field value | |
| $baner_url_first = $first_baner['widget_commercial_url' ]; // get the sub field value | |
| $image_url_first = $baner_image_first['sizes']['large']; | |
| $image_alt_first = $baner_image_first['alt']; | |
| ?> | |
| <article class="card-container home-card inline-baner"> | |
| <a href="<?php echo $baner_url_first ?>"> | |
| <img src="<?php echo $image_url_first ?>" alt="<?php echo $image_alt_first ?>"> | |
| </a> | |
| </article> | |
| <?php | |
| } | |
| } | |
| if( $the_query->current_post === 5 ) { | |
| if ($row_count >= 2) { | |
| $second_baner = $rows[1]; | |
| $baner_image_second = $second_baner['widget_commercial_image' ]; // get the sub field value | |
| $baner_url_second = $second_baner['widget_commercial_url' ]; // get the sub field value | |
| $image_url_second = $baner_image_second['sizes']['large']; | |
| $image_alt_second = $baner_image_second['alt']; | |
| ?> | |
| <article class="card-container home-card inline-baner"> | |
| <a href="<?php echo $baner_url_second ?>"> | |
| <img src="<?php echo $image_url_second ?>" alt="<?php echo $image_alt_second ?>"> | |
| </a> | |
| </article> | |
| <?php | |
| } | |
| } | |
| if( $the_query->current_post === 8 ) { | |
| if ($row_count >= 3) { | |
| $third_baner = $rows[2]; | |
| $baner_image_third = $third_baner['widget_commercial_image' ]; // get the sub field value | |
| $baner_url_third = $third_baner['widget_commercial_url' ]; // get the sub field value | |
| $image_url_third = $baner_image_third['sizes']['large']; | |
| $image_alt_third = $baner_image_third['alt']; | |
| ?> | |
| <article class="card-container home-card inline-baner"> | |
| <a href="<?php echo $baner_url_third ?>"> | |
| <img src="<?php echo $image_url_third ?>" alt="<?php echo $image_alt_third ?>"> | |
| </a> | |
| </article> | |
| <?php | |
| } | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment