Last active
June 2, 2020 18:42
-
-
Save sophiawzey/b9a83da4b0449f4c8e8400e3e83cabec to your computer and use it in GitHub Desktop.
[ACF PHP] using brackets #acf
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 $count = count( get_field( 'field-name' ) ); ?> // can be used for counting rows in a repeater. works well w/ slick slider if you only want a slider on > 2 counts |
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
$image = get_field('video_poster'); | |
$size = 'medium'; | |
if ( ! empty( $image ) ) { | |
// thumbnail | |
$thumb = $image['sizes'][ $size ]; | |
} else { | |
$image = get_field('placeholder_image','option'); | |
$thumb = $image['sizes'][ $size ]; | |
} | |
?> | |
<div class="lozad" data-background-image="<?= $thumb ?>" style="background:url(/wp-content/themes/topfloor-parcel/assets/images/placeholder.png) no-repeat center; background-size: cover;"></div> | |
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 $logo = get_field('header_logo', 'option'); ?> | |
<?php echo file_get_contents( $logo ); ?> |
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 | |
//use the ARRAY so that we can limit image size for the URL and reduce page size | |
$image = get_field( 'image' ); | |
if ( $image ) { | |
$size = 'large'; | |
$alt = $image['alt']; | |
$thumb = $image['sizes'][ $size ]; | |
$width = $image['sizes'][ $size . '-width' ]; | |
$height = $image['sizes'][ $size . '-height' ]; | |
?> | |
<img class="lozad" | |
src="/wp-content/themes/topfloor-parcel/assets/images/placeholder.png" | |
data-src="<?= $thumb ?>" | |
alt="<?= $alt ?>" | |
width="<?= $width ?>" | |
height="<?= $height ?>"/> | |
<?php | |
} |
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 | |
$link = get_field('link'); | |
if( $link ){ | |
$link_url = $link['url']; | |
$link_title = $link['title']; | |
$link_target = $link['target'] ? $link['target'] : '_self'; | |
?> | |
<a class="button" href="<?php echo esc_url( $link_url ); ?>" target="<?php echo esc_attr( $link_target ); ?>"><?php echo esc_html( $link_title ); ?></a> | |
<?php }; ?> |
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 | |
// for a SINGLE post object | |
$post_object = get_field('post_object'); | |
if( $post_object ){ | |
// override $post | |
$post = $post_object; | |
setup_postdata( $post ); | |
?> | |
<div> | |
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3> | |
<span>Post Object Custom Field: <?php the_field('field_name'); ?></span> | |
</div> | |
<?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?> | |
<?php }; ?> |
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
$post_objects = get_field('post_objects'); | |
if( $post_objects ){ ?> | |
<ul> | |
<?php foreach( $post_objects as $post){ // variable must be called $post (IMPORTANT) ?> | |
<?php setup_postdata($post); ?> | |
<li> | |
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> | |
<span>Post Object Custom Field: <?php the_field('field_name'); ?></span> | |
</li> | |
<?php } ?> | |
</ul> | |
<?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?> | |
<?php }; |
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 | |
$posts = get_field('relationship_field_name'); | |
if( $posts ){ ?> | |
<ul> | |
<?php foreach( $posts as $post){ // variable must be called $post (IMPORTANT) ?> | |
<?php setup_postdata($post); ?> | |
<li> | |
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> | |
<span>Custom field from $post: <?php the_field('author'); ?></span> | |
</li> | |
<?php }; ?> | |
</ul> | |
<?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?> | |
<?php }; ?> |
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 | |
// this is a repeater with a single post object | |
if ( have_rows( 'select_teasers' ) ) { ?> | |
<?php while ( have_rows( 'select_teasers' ) ) { | |
the_row(); | |
$post_object = get_sub_field( 'page' ); // IMPORTANT - needs to be sub field | |
if ( $post_object ) { | |
// override $post | |
$post = $post_object; | |
setup_postdata( $post ); | |
?> | |
<div> | |
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3> | |
<span>Post Object Custom Field: <?php the_field( 'field_name' ); ?></span> | |
</div> | |
<?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?> | |
<?php } ?> | |
<?php } ?> | |
<?php } ?> |
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 | |
// an example of using ONE repeater and loopng through twice, first time for tab tables, second time for tab content. | |
if ( have_rows( 'tabs' ) ) { ?> | |
<section class="tabs-container"> | |
<div class="grid-container-small"> | |
<header> | |
<h2 class="title"><?= $title ?></h2> | |
</header> | |
<div class="tabs" data-tabs id="example-tabs"> | |
<?php | |
$row = 1; | |
while ( have_rows( 'tabs' ) ) { | |
the_row(); | |
$title = get_sub_field( 'title' ); | |
?> | |
<li class="tabs-title <?php if ( $row == 1 ) { | |
echo 'is-active'; | |
} ?>"><a href="#panel<?= $row ?>" aria-selected="true"><?= $title ?></a></li> | |
<?php | |
$row ++; | |
} ?> | |
</div> | |
<div class="tabs-content" data-tabs-content="example-tabs"> | |
<?php | |
$row = 1; | |
while ( have_rows( 'tabs' ) ) { | |
the_row(); | |
$left = get_sub_field( 'display_left' ); | |
?> | |
<div class="tabs-panel <?php if ( $row == 1 ) { | |
echo 'is-active'; | |
} ?>" id="panel<?= $row ?>"> | |
<?= $left ?> testing content | |
</div> | |
<?php | |
$row ++; | |
} ?> | |
</div> | |
</div> | |
</section> | |
<?php } ?> |
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 ( have_rows( 'repeater' ) ) { ?> | |
<?php while ( have_rows( 'repeater' ) ) { | |
the_row(); | |
$title = get_sub_field( 'title' ); | |
?> | |
<!-- content here --> | |
<?php } ?> | |
<?php } ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment