Skip to content

Instantly share code, notes, and snippets.

@topleague
Created August 27, 2017 16:20
Show Gist options
  • Save topleague/085ad4e9f3f1a9d891c6f44e68a8c32b to your computer and use it in GitHub Desktop.
Save topleague/085ad4e9f3f1a9d891c6f44e68a8c32b to your computer and use it in GitHub Desktop.
Custom Template for Team
<?php
//* Template Name: Team
//* Force full width content layout
add_filter( 'genesis_site_layout', '__genesis_return_full_width_content' );
//* Add body class to the head of team template
add_filter( 'body_class', 'team_add_body_class' );
function team_add_body_class( $classes ) {
$classes[] = 'team-page';
return $classes;
}
//* Remove the loop condtionally
add_action( 'genesis_before', 'team_remove_loop' );
function team_remove_loop () {
if ( get_query_var( 'paged' ) >= 2 ) {
remove_action('genesis_loop', 'genesis_do_loop');
}
}
//* Add custom loop for team page
add_action( 'genesis_loop', 'team_custom_loop' );
function team_custom_loop() {
global $post;
$args = array(
'post_parent' => $post->ID,
'order' => 'ASC',
'orderby' => 'menu_order',
'post_type' => 'page',
'posts_per_page' => 4,
'paged' => get_query_var( 'paged' ),
);
global $wp_query;
$loop = new WP_Query( $args );
//* Remove actions on entry
$hooks = array(
'genesis_before_entry',
'genesis_entry_header',
'genesis_before_entry_content',
'genesis_entry_content',
'genesis_after_entry_content',
'genesis_entry_footer',
'genesis_after_entry',
);
foreach ( $hooks as $hook ) {
remove_all_actions( $hook );
}
//* Setup the team entry actions
add_filter( 'post_class' , 'custom_team_class' );
add_action( 'genesis_entry_content', 'custom_page_team_image' );
add_action( 'genesis_after_entry_content', 'genesis_entry_header_markup_open' , 5 );
add_action( 'genesis_after_entry_content', 'genesis_entry_header_markup_close', 15 );
add_action( 'genesis_after_entry_content', 'genesis_do_post_title' );
add_action( 'genesis_after_entry_content', 'custom_team_title' );
genesis_custom_loop( wp_parse_args( $query_args, $args ) );
remove_filter( 'post_class' , 'custom_team_class' );
}
//* Add team member featured image
function custom_page_team_image() {
$image = genesis_get_image( array(
'format' => 'html',
'size' => 'team-member',
'attr' => array ( 'alt' => the_title_attribute( 'echo=0' ) ),
) );
if ( $image ) {
printf( '<a href="%s" rel="bookmark">%s</a>', get_permalink(), $image );
}
}
//* Add team title field
function custom_team_title() {
if ( genesis_get_custom_field( 'team_title' ) ) {
$title = '<p class="team-title">' . genesis_get_custom_field( 'team_title' ) . '</p>';
}
echo $title;
}
//* Add one-fourth class to the page team entry
function custom_team_class( $classes ) {
global $wp_query;
$classes[] = 'one-fourth';
if( 0 == $wp_query->current_post % 4 ) {
$classes[] = 'first';
}
return $classes;
}
//* Run the Genesis loop
genesis();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment