Skip to content

Instantly share code, notes, and snippets.

@rgadon107
Created August 19, 2018 03:41
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 rgadon107/cc2f1a2a66ba1e0992bb985e4c6a55c6 to your computer and use it in GitHub Desktop.
Save rgadon107/cc2f1a2a66ba1e0992bb985e4c6a55c6 to your computer and use it in GitHub Desktop.
Render an event venue when calling 'single-event.php'.
add_action( 'genesis_entry_header', __NAMESPACE__ . '\add_content_wrap_markup_open', 3 );
/*
* Add content wrap around Event entry_header & render post thumbnail on single.
*
* @since 1.0.0
*
* return void
*/
function add_content_wrap_markup_open() {
$event_id = (int) get_the_ID();
printf( '<div %s>', genesis_attr( 'before-entry-header-wrap' ) );
echo add_venue_image_to_single_event();
}
/*
* Add an event venue image to the single-event template.
*
* @since 1.0.0
*
* @return void
*/
function add_venue_image_to_single_event() {
if ( is_post_type_archive( 'events' ) ) {
return '';
}
return render_event_venue_image( $event_id );
}
@hellofromtonya
Copy link

@rgadon107 You split it out into a separate function, i.e. add_venue_image_to_single_event() , when you need to reuse it in other places. If no and it's a singular usage for just this, then do this:

function add_content_wrap_markup_open() {
	$event_id = (int) get_the_ID();

	printf( '<div %s>', genesis_attr( 'before-entry-header-wrap' ) );

	if ( ! is_post_type_archive( 'events' ) ) {
             render_event_venue_image( $event_id );
        }
}

You don't need to echo because the function render_event_venue_image( $event_id ); is doing (or should do) the rendering. Why? Because it says its expected behavior is to render the event venue image.

@rgadon107
Copy link
Author

rgadon107 commented Aug 19, 2018

@hellofromtonya: Given that I only plan to get the image for the single-events template, then it makes sense to use the conditional in the function add_content_wrap_markup_open() and call the function render_event_venue_image( $event_id ).

Your point about about reusing the 'get_image' function for other use cases in a project is a good one. In that situation, it would make sense then to build the 'get_image()' function in a more generic way to use as a helper function or method throughout the project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment