Support

Home Forums Event Espresso Premium Customizing Event Archives and People Archives

Customizing Event Archives and People Archives

Posted: September 24, 2017 at 3:12 pm

Viewing 8 reply threads


sogtalks@gmail.com

September 24, 2017 at 3:12 pm

Hi,

I have added (with ACF) some custom fields in Event Details with sponsor information including a sponsor logo. Works as expected on the event details page, great. I would like to include that logo at the bottom of the content on the Event Archive page. This also involves the People addon.

  • People description is automatically loaded to event archive, great!
  • I created an archive-espresso-events file, placed in child-theme.
  • In admin panel disabled Use Custom Display Order
  • Commented add_filter… in content-espresso_events
  • Made modification to that file, okay
  • Now I lose the People description with those modifications

So,

  1. I would like to add the sponsor logo at the bottom of each event archive entry
  2. and include the People description
  3. Can you guide me please. Thank you for your help.


Josh

  • Support Staff

September 25, 2017 at 10:27 am

With regards to this item:

Made modification to that file, okay

May I ask what were the modifications and to which file exactly?


sogtalks@gmail.com

September 25, 2017 at 10:55 am

Hi Josh,

After disabling “Use Custom Display Order” in the admin panel, I opened the file
content-espresso_events and in the commented instructions it says to “if you are creating a custom template based on this file,
* and do not wish to use the template display order controls in the admin,
* then remove the following filter” => //add_filter( 'FHEE__content_espresso_events__template_loaded', '__return_true' );

In the file archive-espresso-events made this modification `<!– .page-header –>
<?php
while ( have_posts() ) :
the_post();
//get_template_part( ‘content’, get_post_format(‘archive’) );
get_template_part( ‘content-espresso_events’ );
endwhile;
zerif_paging_nav();
else :
get_template_part( ‘content’, ‘none’ );
endif;
function ee_event_sponsor_logo() {
?>
<div class=”sponsordetails”>
<h3>Event Sponsor</h3>
<a href=”<?php the_field( “sponsor_website” )?>”><img align=”right” src=”<?php the_field( “sponsor_logo_image” )?>”></a>
<?php the_field( “sponsor_bio” )?>
</div>
<?php }
add_action( ‘AHEE_event_details_before_the_content’, ‘ee_event_sponsor_logo’ );

?>
</main><!– #main –>`

Thanks for your help.


Josh

  • Support Staff

September 25, 2017 at 2:26 pm

It may be too late to hook a callback function to AHEE_event_details_before_the_content directly in the template. Usually these are added to the theme’s functions.php file or even better into a site specific plugin.

The ee_event_sponsor_logo() function would be best moved into a functions file too.

With regards to the ee_event_sponsor_logo() function, it doesn’t appear to have any means of checking for the current post ID. the
AHEE_event_details_before_the_content action hook can access the $post object, so the following changes to your code will ensure you have the correct post to work with:

function ee_event_sponsor_logo( $post ) {
  if (!function_exists('the_field')) {
    return; // get out! ACF isn't activated!
  }
?>
  <div class="sponsordetails">
  <h3>Event Sponsor</h3>
  <a href="
    <?php the_field( 'sponsor_website', $post->ID ); ?>
    "><img align="right" src="
    <?php the_field( 'sponsor_logo_image', $post->ID ); ?>
    ">
  </a>
  <?php the_field( 'sponsor_bio', $post->ID ); ?>
  </div>
  <?php 
}
add_action( 'AHEE_event_details_before_the_content', 'ee_event_sponsor_logo' );

Since you mentioned you’re already editing the content-espresso_events.php you could also add the markup directly to that template to add the sponsor logo instead of using the action hook.

You can also copy the code from the People add-on’s /public/templates/content-espresso_events-people.php template into your custom templates. Please be sure to put the custom templates into a child theme to load them from there in case you need to update the WP theme later.


sogtalks@gmail.com

September 30, 2017 at 2:00 pm

Thanks Josh,

I incorporated that code and added a bit to hide the div if the value XXX is empty now the div is hidden when empty but I am getting the image and the image URL when it’s true. What am I missing?

function ee_event_sponsor_logo( $post ) {
  if (!function_exists('the_field')) {
    return; // get out! ACF isn't activated!

}

?>

<?php if( $field = get_field('sponsor_logo_image') ): ?>
  <div class="sponsordetails_archive">
  <h3>Event Sponsor</h3>
  <div class="sponsor_logo_archive"><a href="<?php the_field( 'sponsor_website', $post->ID ); ?>" target="_blank"><img align="left" src="<?php the_field( 'sponsor_logo_image', $post->ID ); ?>"></a></div>
  <div class="sponsor_bio_archive"><?php the_field( 'sponsor_bio', $post->ID ); ?></div>
  </div>
    <p><?php echo $field; ?></p>
<?php endif; ?>

  
  

  <?php 
}
add_action( 'AHEE_event_details_after_the_content', 'ee_event_sponsor_logo' );

Thank you. Very helpful.


Tony

  • Support Staff

October 2, 2017 at 2:39 am

I incorporated that code and added a bit to hide the div if the value XXX is empty now the div is hidden when empty but I am getting the image and the image URL when it’s true.

Is that a typo?

You are getting the image URL when its true? That seems to be the expected output.


sogtalks@gmail.com

October 2, 2017 at 9:14 am

Tony,

Argh! Yes, that was a typo, it was a placeholder for “sponsor_logo_image”. What is happening is that I am getting the image and it is linked but I am also getting the image URL in text written just to the right of the image. I do not want the image URL to be visble.

Thank you for your patience.


Josh

  • Support Staff

October 2, 2017 at 10:05 am

This is the line of your code that you likely do not want:

<p><?php echo $field; ?></p>


sogtalks@gmail.com

October 2, 2017 at 2:35 pm

Josh,

Can’t see the forest for the trees. Sorry for wasting your time. Appreciate the support.

For anyone else looking to add fields to the People Archives, here’s what we ended up with, thanks to Tony and Josh:

function ee_event_sponsor_logo( $post ) {
  if (!function_exists('the_field')) {
    return; // get out! ACF isn't activated!

}

?>

  <?php if( $field = get_field('sponsor_logo_image') ): ?>
  <div class="sponsordetails_archive">
  <h3>Event Sponsor</h3>
  <div class="sponsor_logo_archive"><a href="<?php the_field( 'sponsor_website', $post->ID ); ?>" target="_blank"><img align="left" src="<?php the_field( 'sponsor_logo_image', $post->ID ); ?>"></a></div>
  <div class="sponsor_bio_archive"><?php the_field( 'sponsor_bio', $post->ID ); ?></div>
  </div>
<?php endif; ?>
  
  <?php 
}
add_action( 'AHEE_event_details_after_the_content', 'ee_event_sponsor_logo' );
Viewing 8 reply threads

The support post ‘Customizing Event Archives and People Archives’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso