Skip to content

Instantly share code, notes, and snippets.

@gregoirenoyelle
Last active March 15, 2018 14:39
Show Gist options
  • Save gregoirenoyelle/b5282edb617dd9916119331713339a23 to your computer and use it in GitHub Desktop.
Save gregoirenoyelle/b5282edb617dd9916119331713339a23 to your computer and use it in GitHub Desktop.
ACF Custom Widget
<?php
//* Single Portfolio
//* Enlever sidebar classique
remove_action( 'genesis_sidebar', 'genesis_do_sidebar');
add_action( 'genesis_sidebar', 'gn_sidebar');
function gn_sidebar() {
global $post;
//** check ACF
if ( !function_exists('get_field') ) return;
//** Variables
$output = '';
$widget_open = '<section class="widget"><div class="widget-wrap">';
$widget_close = '</div></section>';
$training_author = get_field('gn_training_author');
$widget_info = get_field('gn_widget_info', false, false);
//** Widget Recherche
$output .= $widget_open;
$output .= get_search_form();
$output .= $widget_close;
//** Widget Author
if ($training_author) :
$post = $training_author;
setup_postdata( $post);
$output .= $widget_open;
$output .= '<h4 class="widget-title widgettitle">Votre Formateur</h4>';
$output .= get_the_post_thumbnail( $post->ID, 'thumbnail', array('class' => 'team-image') );
$output .= sprintf('<h5 class="trainer">%s</h5>', get_the_title( $post) );
$output .= get_field('gn_training_author_bio');
$output .= $widget_close;
wp_reset_postdata();
endif;
//** Widgets info
if ($widget_info) :
$args = array(
'post_type' => 'information',
'posts_per_page' => 30,
'post__in' => $widget_info,
'orderby' => 'post__in'
);
$query = new WP_Query($args);
// boucle widget
while ( $query->have_posts() ) : $query->the_post();
$widget_title = get_field('gn_widget_title');
$output .= $widget_open;
$output .= sprintf('<h4 class="widget-title widgettitle">%s</h4>', $widget_title );
// display content with p tag
$output .= wpautop($post->post_content);
$output .= $widget_close;
endwhile;
wp_reset_postdata();
endif;
//** Display content
echo $output;
}
genesis();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment