Community Forums › Forums › Archived Forums › General Discussion › Advanced Custom Field and Genesis column classes
Tagged: advanced custom field, Columns
- This topic has 3 replies, 2 voices, and was last updated 10 years, 7 months ago by Genesis Developer.
-
AuthorPosts
-
April 10, 2014 at 5:45 am #99454japser123Member
Hi there,
I'm having some problems trying to get the Advanced Custom Field plugin to play nicely with the Genesis column classes.
I'm working on a portfolio template with a grid layout consisting of items (images and overlayed text) that I derive from ACF using the repeater addon.
The problem I'm dealing with is that to start each row (I'm using 3 columns here by adding the class 'one-third') the first item should also have the added class 'first'.
The page template I'm using to load the ACF data into now looks like the code below:
<?php /* Template Name: Portfolio */ ?> <?php add_action( 'genesis_entry_content', 'abte_my_custom_function' ); function abte_my_custom_function() { ?> <?php if( have_rows('ACF_portfolio') ): ?> <ul class="portfolio"> <?php while( have_rows('ACF_portfolio') ): the_row(); // vars $image = get_sub_field('image'); $content = get_sub_field('description'); $link = get_sub_field('link'); ?> <li class="one-third"> <?php if( $link ): ?> <a href="<?php echo $link; ?>"> <?php endif; ?> <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt'] ?>" /> <?php if( $link ): ?> </a> <?php endif; ?> <?php echo $content; ?> </li> <?php endwhile; ?> </ul> <?php endif; ?> <?php } ?> <?php genesis(); ?>
This works but gives every item only the 'one-third' class, I need it to give every third repeated div the class 'first'.
Looking for a solution I've found this: http://thewebprincess.com/using-php-counter-add-class-every-third-list-item but I can't get it to work with my code.
Anyone has any suggestions?
Thank you!
JasperApril 10, 2014 at 6:44 am #99465Genesis DeveloperMembertry this
<?php /* Template Name: Portfolio */ ?> <?php add_action( 'genesis_entry_content', 'abte_my_custom_function' ); function abte_my_custom_function() { ?> <?php if( have_rows('ACF_portfolio') ): $counter = 1;?> <ul class="portfolio"> <?php while( have_rows('ACF_portfolio') ): the_row(); // vars $image = get_sub_field('image'); $content = get_sub_field('description'); $link = get_sub_field('link'); $is_first = ($counter % 3 == 1) ? "first" : ''; ?> <li class="one-third <?php echo $is_first;?>"> <?php if( $link ): ?> <a href="<?php echo $link; ?>"> <?php endif; ?> <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt'] ?>" /> <?php if( $link ): ?> </a> <?php endif; ?> <?php echo $content; ?> </li> <?php $counter++; endwhile; ?> </ul> <?php endif; ?> <?php } ?> <?php genesis(); ?>
April 10, 2014 at 7:21 am #99475japser123MemberThis is working now! Using the counter is very clever indeed.
Thank you so much!
April 10, 2014 at 7:22 am #99476Genesis DeveloperMemberYou are welcome.
-
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.