Advanced Custom Field and Genesis column classes

Community Forums Forums General Discussion Advanced Custom Field and Genesis column classes

This topic is: resolved

This topic contains 3 replies, has 2 voices, and was last updated by  genwrock 5 months, 2 weeks ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #99454

    japser123
    Member
    Post count: 5

    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!
    Jasper

    • This topic was modified 5 months, 2 weeks ago by  japser123.
    • This topic was modified 5 months, 2 weeks ago by  japser123.
    #99465

    genwrock
    Member
    Post count: 586

    try 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(); ?>

    My Genesis Child Themes Work | Please Follow Me on Twitter If I’ve helped.

    #99475

    japser123
    Member
    Post count: 5

    This is working now! Using the counter is very clever indeed.

    Thank you so much!

    #99476

    genwrock
    Member
    Post count: 586

    You are welcome.


    My Genesis Child Themes Work | Please Follow Me on Twitter If I’ve helped.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.