Support

Home Forums Event Espresso Premium If no upcoming events in a category – how to present custom message

If no upcoming events in a category – how to present custom message

Posted: January 29, 2016 at 5:40 am


Andrew Moreton

January 29, 2016 at 5:40 am

Hi – I run training courses – some are scheduled to run regularly and I use Event Espresso 4 to manage these – some are only available for bespoke, custom bookings, which I book in manually.

On my course pages I’m using [ESPRESSO_EVENTS category_slug=”course-name”] to get a list of upcoming scheduled courses.

If there are no scheduled upcoming courses nothing displays – however instead of this, if there are no scheduled upcoming courses I’d like to diaply an alternative message to remind my visitors that they could always book an bespoke course instead.

To precis: I want to display a custom message if there are no courses in that category upcoming.

thanks!

Andrew


Lorenzo Orlando Caum

  • Support Staff

January 29, 2016 at 9:43 am

Hi Andrew,

Thats a really good idea. I looked at this on my current theme on my testing site and here is how I set it up.

The [ESPRESSO_EVENTS] shortcode uses an archive.php theme template in your theme folder. You can create a separate template for Event Espresso to use.

1) Create a child theme that will hold your customizations:

https://codex.wordpress.org/Child_Themes#How_to_Create_a_Child_Theme

2) Duplicate an existing parent theme template such as an archive.php and then rename to archive-espresso_events.php. Now you’ll want to change the messaging that is shown when no content (e.g. events) are available.

3) Open the new archive-espresso_events.php for editing. Here is what mine looks like:

http://cl.ly/1u36293S3y2f

The highlighted are is the reference to the theme content file that is used when there is no content available.

You may see something similar but it won’t be an exact match since you are not using the same theme: http://cl.ly/3G1s2i2l0W1v

4) The next step is to duplicate the content-none.php (note your filename may be different) that is being used and create another one. Then that new file name should be referenced in the archive-espresso_events.php file.

For example, here I changed it to look for a file called content-noevents.php: http://cl.ly/082e3U2Q0M0U

5) Then I edited the content-noevents.php file to have new messaging:

http://cl.ly/301b1R3f2L20


Lorenzo


Andrew Moreton

February 12, 2016 at 6:37 am

Hi Lorenzo,

Sorry for the very long wait for me to get back – I stumbled over a bunch of other issues which I’ve now resolved. Meanwhile…

I’ve now tried your suggestion of adding an else statement to the loop in my archive.php or duplicated archive-event_espresso.php templates.

However, neither of these templates seem to be providing anything that’s being generated by my [ESPRESSO_EVENTS] shortcode.

Even if I delete all the contents of these files the [ESPRESSO_EVENTS] shortcode still generates content (if there are upcoming events that is) – where might I find the source for the [ESPRESSO_EVENTS] shortcode if not in my themes archive.php or archive-event_espresso.php?

thanks!

Andrew


Josh

  • Support Staff

February 12, 2016 at 8:59 am

Hi Andrew,

It turns out the shortcode doesn’t use the templates that Lorenzo referred to. If you look in loop-espresso_events.php you’ll find that it will load
espresso_get_template_part( 'content', 'espresso_events-shortcode' );
if there are events. If no events, it looks for this:
espresso_get_template_part( ‘content’, ‘none’ );

If your theme has a content-none.php file, that’s the file to edit, and if you can post the contents of the content-none.php file in a pastebin or gist, we can take a look and give you further suggestions on how to add a conditional check for events and a custom message there.


Andrew Moreton

February 16, 2016 at 7:15 am

Thanks Josh, that seems to work.
I’ve created a content-none.php which is now being used by the shortcode.

thanks,

Andrew


Josh

  • Support Staff

February 16, 2016 at 8:30 am

Yeah that will work.

The support post ‘If no upcoming events in a category – how to present custom message’ 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