I'm new to utilizing PHP fully, so I think this is just my lack of understanding the proper syntax.
I've got a home page that's being built with WordPress and Advanced Custom Fields. The images are the same thing over and over again for different data, so proper time to create a function correct?
This is my function:
<?php
function homeMobImgLayout($flexibleLayout) {
$pageID = '333';
// check if the flexible content field has rows of data
if( have_rows('$flexibleLayout', $pageID ) ):
// loop through the rows of data
while ( have_rows('$flexibleLayout', $pageID ) ) : the_row();
// 100% Image
if( get_row_layout() == 'image_100' ):
$img = get_sub_field('img');
$alt = get_sub_field('alt');
echo '<div class="imagePod width100 clearfix">';
echo '<img src="' . $img . '" alt="' . $alt . '" />';
echo '</div>';
// 50% Image
elseif( get_row_layout() == 'image_50' ):
$img = get_sub_field('img');
$alt = get_sub_field('alt');
echo '<div class="imagePod width50 clearfix">';
echo '<img src="' . $img . '" alt="' . $alt . '" />';
echo '</div>';
endif;
endwhile;
else :
// no layouts found
endif;
}
?>
The only thing that needs to change with each instance of the function call is the two places where I've got the variable $flexibleLayout
(if( have_rows('$flexibleLayout', $pageID ) ):
while ( have_rows('$flexibleLayout', $pageID ) ) : the_row();
So then with each instance I call the function, I though I just passed what I wanted this value to be.
Examples:
<?php
homeMobImgLayout("pet_boarding_imgs");
?>
and
<?php
homeMobImgLayout("dog_boarding_imgs");
?>
Where is my understanding and/or syntax incorrect?