Last active
May 1, 2018 09:37
-
-
Save ThomasLarge/06a8c863f35778c6c5e3e8ff6ce1015a to your computer and use it in GitHub Desktop.
ACF Helpers
This file contains 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
# Include panels - acf pro | |
<?php | |
if( get_field('content_panels') ): | |
while ( has_sub_field('content_panels') ) : | |
if( get_row_layout() == 'columns_panel' ): | |
get_template_part( 'panels/columns' ); | |
elseif( get_row_layout() == 'two_col_image_left' ): | |
get_template_part( 'panels/two-col-left' ); | |
endif; | |
endwhile; | |
endif; ?> | |
# Add columns classes to the number of acf rows | |
<?php if( have_rows('columns') ): | |
// Vars | |
$colIndex = 0; | |
$col_HTML = ''; | |
while ( have_rows('columns') ) : the_row(); $colIndex++; | |
$column_text = get_sub_field('content'); | |
// This is the HTML that is printed | |
$col_HTML.= "<div class=\"[REPLACECOLCSS]\">$column_text</div>"; | |
endwhile; | |
// pre define the allowed columns | |
$allowed_classnames = array( | |
1 => 'medium-8 medium-centered columns', | |
2 => 'medium-4 medium-offset-2 columns', | |
3 => 'medium-3 columns', | |
); | |
// Make sure you alway limit the amount of rows in ACF | |
// set a default classname | |
$classname_to_use = $allowed_classnames[1]; | |
// check if the $number_of_cols exist in the predefined classnames | |
if ( array_key_exists( $colIndex , $allowed_classnames ) ) { | |
// set the classname to be used | |
$classname_to_use = $allowed_classnames[$colIndex]; | |
} | |
echo str_replace( '[REPLACECOLCSS]', $classname_to_use, $col_HTML ); | |
?> | |
<?php endif; ?> |
This file contains 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 if ( get_field( 'field_name' ) ): ?> | |
This is displayed wen the field_name is TRUE or has a value. | |
<?php else: // field_name returned false ?> | |
This is displayed when the field is FALSE, NULL or the field does not exist. | |
<?php endif; // end of if field_name logic ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment