Skip to content

Instantly share code, notes, and snippets.

@amberhinds
Created April 19, 2016 15:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amberhinds/a17dddadf9b69d096c0577155cfb2e89 to your computer and use it in GitHub Desktop.
Save amberhinds/a17dddadf9b69d096c0577155cfb2e89 to your computer and use it in GitHub Desktop.
Example of a CPT single post that uses ACF
<?php
/* Add custom body class */
add_filter( 'body_class', 'techup_featured_body_class' );
function techup_featured_body_class( $classes ) {
$classes[] = 'techup-featured-image recruiting-event';
return $classes;
}
/* Force full width content */
add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_full_width_content' );
/* Add extra wrap to .entry-header */
add_action('genesis_entry_header', 'techup_start_entry_header_wrap', 5);
function techup_start_entry_header_wrap() {
echo '<div class="wrap"><!-- start entry header .wrap --><div class="event-details">';
}
add_action('genesis_entry_header', 'techup_close_entry_header_wrap', 11);
function techup_close_entry_header_wrap() {
echo '</div><!-- end entry header .wrap --></div>';
}
/* Change Entry Title */
//* Remove the entry title (requires HTML5 theme support)
remove_action( 'genesis_entry_header', 'genesis_do_post_title' );
add_action('genesis_entry_header', 'add_custom_event_title_info');
function add_custom_event_title_info() {
// Event Title
$eventtitle = get_field('event_name');
if ( $eventtitle ) {
echo '<h1 class="entry-title" itemprop="headline">' . $eventtitle . '</h1>';
} else {
genesis_do_post_title();
}
// Event Date & Location
$eventdate = get_field('event_date');
$eventstart = get_field('event_start_time');
$eventend = get_field('event_end_time');
if ( $eventdate ) {
echo '<p class="event-info">' . $eventdate . ' ' . $eventstart . ' - ' . $eventend . ', ' . get_the_title() . '</p>';
} else {
return;
}
}
/* Enqueue backstretch and backstretch set */
add_action( 'wp_enqueue_scripts', 'techup_featured_template_scripts' );
function techup_featured_template_scripts() {
wp_enqueue_script( 'techup-backstretch', get_stylesheet_directory_uri() . '/js/techup-backstretch.js', array( 'jquery' ), '1.0.0', true );
wp_enqueue_script( 'techup-backstretch-set', get_stylesheet_directory_uri() . '/js/techup-backstretch-set.js' , array( 'jquery', 'techup-backstretch' ), '1.0.0', true );
wp_enqueue_script( 'acf-map', get_stylesheet_directory_uri() . '/js/acf-map.js', array( 'jquery' ), '1.0.0', true );
wp_enqueue_script( 'google-maps', 'https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false', array( 'jquery' ), '1.0.0', true );
}
/* Set the background image on the .entry-header div */
add_action( 'genesis_after_entry', 'techup_set_background_image' );
function techup_set_background_image() {
$image = array( 'src' => get_field('featured_image'));
$div = ".entry-header";
wp_localize_script( 'techup-backstretch-set', 'techupBackstretchImages', $image );
wp_localize_script( 'techup-backstretch-set', 'techupBackstretchDiv', $div );
}
/* Add featured image */
add_action('genesis_before_entry_content', 'add_featured_event_icon');
function add_featured_event_icon() {
/*echo '<div class="event-icon">';
echo the_post_thumbnail( 'thumbnail' );
echo '</div>';*/
echo '<div class="main-content-wrap">';
}
add_action('genesis_after_entry_content', 'add_event_sponsors', 1);
function add_event_sponsors() {
// check if the repeater field has rows of data
if( have_rows('event_sponsors') ):
echo '<div class="hiring-partners sidebar sidebar-primary widget-area">';
echo '<div class="sponsor-group">';
echo '<h4 class="widgettitle">Host</h4>';
// loop through the rows of data
while ( have_rows('event_sponsors') ) : the_row();
// display a sub field value
echo '<a target="_blank" href="' . get_sub_field('sponsor_url') . '" title="' . get_sub_field('sponsor_name') .'">
<img src="' . get_sub_field('sponsor_logo') . '" alt="' . get_sub_field('sponsor_name') . '"></a>';
endwhile;
echo '</div>';
else :
// no rows found
endif;
// check if the repeater field has rows of data
if( have_rows('partner_sponsors') ):
echo '<div class="sponsor-group">';
echo '<h4 class="widgettitle">Partners</h4>';
// loop through the rows of data
while ( have_rows('partner_sponsors') ) : the_row();
// display a sub field value
echo '<a target="_blank" href="' . get_sub_field('sponsor_url') . '" title="' . get_sub_field('sponsor_name') .'">
<img src="' . get_sub_field('sponsor_logo') . '" alt="' . get_sub_field('sponsor_name') . '"></a>';
endwhile;
echo '</div>';
else :
// no rows found
endif;
// check if the repeater field has rows of data
if( have_rows('community_partners') ):
echo '<div class="sponsor-group">';
echo '<h4 class="widgettitle">Community Partners</h4>';
// loop through the rows of data
while ( have_rows('community_partners') ) : the_row();
// display a sub field value
echo '<a target="_blank" href="' . get_sub_field('sponsor_url') . '" title="' . get_sub_field('sponsor_name') .'">
<center><img src="' . get_sub_field('sponsor_logo') . '" alt="' . get_sub_field('sponsor_name') . '"></center></a>';
endwhile;
echo '</div>';
else :
// no rows found
endif;
echo '</div></div>';
}
add_action('genesis_after_entry_content', 'add_event_details', 5);
function add_event_details() {
$eventdate = get_field('event_date');
$eventstart = get_field('event_start_time');
$eventend = get_field('event_end_time');
if ( $eventdate ) {
echo '<h2 class="event-date-time">' . $eventdate . ' ' . $eventstart . ' - ' . $eventend . '</h2>';
} else {
return;
}
$eventbrite = get_field('eventbrite_embed_code');
if ( $eventbrite ) {
echo '<div class="eventbrite">' . $eventbrite . '</div>';
} else {
return;
}
$images = get_field('event_images');
if( $images ): ?>
<div class="event-gallery">
<hr>
<p style="text-align: center;"><strong>TechUP // Not Your Typical Career Fair</strong></p>
<hr>
<ul>
<?php foreach( $images as $image ): ?>
<li>
<a href="<?php echo $image['url']; ?>">
<center><img src="<?php echo $image['sizes']['event-gallery']; ?>" alt="<?php echo $image['alt']; ?>" /></center>
</a>
<p><?php echo $image['caption']; ?></p>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php endif;
$location = get_field('event_location');
if( !empty($location) ):
?>
<div class="event-location">
<h3 class="address"><strong> <?php the_field('event_location_name'); ?></strong></h3>
<p><?php echo $location['address']; ?></p>
</div>
<div class="acf-map">
<div class="marker" data-lat="<?php echo $location['lat']; ?>" data-lng="<?php echo $location['lng']; ?>">
<h4><?php the_field('event_name'); ?></h4>
<p class="address"><strong> <?php the_field('event_location_name'); ?></strong><br/>
<?php echo $location['address']; ?><br/>
<a class="directions" target="_blank" href="https://www.google.com/maps?saddr=My+Location&daddr=<?php echo $location['lat'] . ',' . $location['lng']; ?>"><?php _e('Get Directions','roots'); ?></a>
</p>
</div>
</div>
<?php endif;
}
//* Remove the entry footer markup (requires HTML5 theme support)
remove_action( 'genesis_entry_footer', 'genesis_entry_footer_markup_open', 5 );
remove_action( 'genesis_entry_footer', 'genesis_entry_footer_markup_close', 15 );
genesis();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment