Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@hellofromtonya hellofromtonya commented Aug 19, 2018

@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

This comment has been minimized.

Copy link
Owner Author

@rgadon107 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
You can’t perform that action at this time.