Last active
February 4, 2018 01:43
-
-
Save srikat/e9dd51a7bbf982673a7b to your computer and use it in GitHub Desktop.
Single CPT template in Genesis to display ACF custom fields incl. a Gallery field as a Slider. http://sridharkatakam.com/single-cpt-template-genesis-display-acf-custom-fields-including-gallery-field-slider/
This file contains hidden or 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
| jQuery(function( $ ){ | |
| $('.flexslider').flexslider({ | |
| animation: "slide", | |
| // pausePlay: true | |
| pauseOnHover: true | |
| }); | |
| }); |
This file contains hidden or 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 | |
| //* Do NOT include the opening php tag | |
| //* Add new image size | |
| add_image_size( 'project-image', 683, 0, true ); |
This file contains hidden or 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 | |
| //* Enqueue FlexSlider | |
| add_action( 'wp_enqueue_scripts', 'sk_enqueue_scripts' ); | |
| function sk_enqueue_scripts() { | |
| wp_enqueue_style( 'flexslider-styles', get_stylesheet_directory_uri(). '/css/flexslider.css', array(), CHILD_THEME_VERSION ); | |
| wp_enqueue_script( 'flexslider', get_stylesheet_directory_uri() . '/js/jquery.flexslider-min.js', array( 'jquery' ), '', true ); | |
| wp_enqueue_script( 'flexslider-init', get_stylesheet_directory_uri() . '/js/flexslider-init.js', array( 'flexslider' ), '1.0.0', true ); | |
| } | |
| //* Force full width content | |
| add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_full_width_content' ); | |
| //* Remove Post Info | |
| remove_action( 'genesis_entry_header', 'genesis_post_info', 12 ); | |
| //* Remove Post Meta | |
| remove_action( 'genesis_entry_footer', 'genesis_entry_footer_markup_open', 5 ); | |
| remove_action( 'genesis_entry_footer', 'genesis_entry_footer_markup_close', 15 ); | |
| remove_action( 'genesis_entry_footer', 'genesis_post_meta' ); | |
| //* Display custom fields above entry content | |
| add_action( 'genesis_entry_content', 'sk_do_post_content', 9 ); | |
| function sk_do_post_content() { | |
| echo '<div class="one-half first">'; | |
| $images = get_field('project_images'); | |
| if( $images ) { ?> | |
| <div id="slider" class="flexslider"> | |
| <ul class="slides"> | |
| <?php foreach( $images as $image ): ?> | |
| <li> | |
| <img src="<?php echo $image['sizes']['project-image']; ?>" alt="<?php echo $image['alt']; ?>" /> | |
| </li> | |
| <?php endforeach; ?> | |
| </ul> | |
| </div> | |
| <?php } elseif( has_post_thumbnail() ) { | |
| $image_args = array( | |
| 'size' => 'project-image', | |
| ); | |
| genesis_image( $image_args ); | |
| } else { | |
| echo '<img src="'. get_stylesheet_directory_uri() .'/images/project-image.gif" alt="Default Project Image" />'; | |
| } | |
| echo '</div>'; | |
| echo '<div class="one-half">'; | |
| sk_display_custom_fields(); | |
| echo '</div>'; | |
| echo '<div class="clear"></div>'; | |
| } | |
| //* Function to display values of custom fields (if not empty) | |
| function sk_display_custom_fields() { | |
| $client_name = get_field( 'client_name' ); | |
| $date_completed = get_field( 'date_completed' ); | |
| $techniques_used = get_field( 'techniques_used' ); | |
| $project_link = get_field( 'project_link' ); | |
| if ( $client_name || $date_completed || $techniques_used || $project_link ) { | |
| echo '<div class="project-meta">'; | |
| if ( $client_name ) { | |
| echo '<p><strong>Client Name</strong>: ' . $client_name . '</p>'; | |
| } | |
| if ( $date_completed ) { | |
| echo '<p><strong>Date Completed</strong>: ' . $date_completed . '</p>'; | |
| } | |
| if ( $techniques_used ) { | |
| echo '<p><strong>Techniques Used</strong>: ' . $techniques_used . '</p>'; | |
| } | |
| if ( $project_link ) { | |
| echo '<a target="_blank" href="' . $project_link . '" class="button">View Project</a>'; | |
| } | |
| echo '</div>'; | |
| } | |
| } | |
| //* Previous and Next Post navigation | |
| add_action('genesis_entry_content', 'sk_custom_post_nav'); | |
| function sk_custom_post_nav() { | |
| echo '<div class="prev-next-post-links">'; | |
| previous_post_link('<div class="previous-post-link">« %link</div>', '<strong>%title</strong>' ); | |
| next_post_link('<div class="next-post-link">%link »</div>', '<strong>%title</strong>' ); | |
| echo '</div>'; | |
| } | |
| genesis(); |
This file contains hidden or 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
| .entry-content .flexslider ul, | |
| .entry-content .flexslider ol { | |
| margin-bottom: 0; | |
| margin-left: 0; | |
| } | |
| .slides p { | |
| margin-bottom: 0; | |
| } | |
| .entry-content .flexslider ul > li { | |
| list-style-type: none; | |
| } | |
| .flexslider .flex-control-nav { | |
| bottom: -50px; | |
| } | |
| .project-meta { | |
| margin-left: 20px; | |
| margin-bottom: 40px; | |
| } | |
| .clear { | |
| clear: both; | |
| } | |
| h1, | |
| h3 { | |
| margin-top: 40px; | |
| } | |
| .entry-header { | |
| margin-bottom: 40px; | |
| } | |
| .prev-next-post-links { | |
| overflow: hidden; | |
| margin-top: 40px; | |
| } | |
| .previous-post-link { | |
| float: left; | |
| } | |
| .next-post-link { | |
| float: right; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment