Support

Home Forums Event Espresso Premium Is it possible to have multiple custom single event page layouts?

Is it possible to have multiple custom single event page layouts?

Posted: May 14, 2020 at 12:12 pm


Nick

May 14, 2020 at 12:12 pm

Hi,

A while back I created a custom layout for single event pages: content-espresso_events.php – which I placed in my child theme folder.

I would like to create a different layout for specific events and wonder whether it’s possible to have more than one single event template which is selectively applied to some events.

Thanks,

Nick


Tony

  • Support Staff

May 15, 2020 at 4:25 am

Hi Nick,

Yes, it is, but you’ll need to go a little wider scope than just content-espresso_events.php. What you are looking for they are called Custom Page Templates in WordPress and you can find details on them here:

https://developer.wordpress.org/themes/template-files-section/page-template-files/

In your case you would need to work from single-espresso_events.php (which would be a copy of your themes single.php or page.php template depending on the look your want and then create templates specific for the espresso_events post type:

https://developer.wordpress.org/themes/template-files-section/page-template-files/#creating-page-templates-for-specific-post-types


Nick

May 15, 2020 at 5:08 am

Thanks Tony. Is it the case that different event espresso events can have different post types then?

I actually realise that I may be able to use the custom pages I already have and show and hide content using css and the post id for each event. That might be the simplest method for my purposes.

There’s just one thing I can’t work out how to do, though I would have thought that this would be somehow built in to EE. I am setting a limit of 1 ticket per booking for this recurring event. This means that the drop down menu for selecting the number of tickets at each price point doesn’t show. However the name of the table column remains as “QTY” when I think it should change to something like “Select”. Is it possible to achieve this?

Here is the link to the page again: http://opendialogueapproach.co.uk/events/weekly-group/


Tony

  • Support Staff

May 15, 2020 at 5:25 am

Is it the case that different event espresso events can have different post types then?

No, may I ask what makes you think that from the above? Just so I know what to add details on if this comes up again.

Event Espresso events will always have a post type of espresso_events

WordPress uses the template hierarchy to display your posts (including EE events): https://developer.wordpress.org/themes/basics/template-hierarchy/

So for a single EE event, it will (in this order) check for:

$custom.php (If selected on the post, this is the custom post template I mentioned above)
single-$posttype-$slug.php (single-espresso_events-my-event.php would be used for an EE event with the slug my-event, it allows you to target specific posts but generally, its not used much)
single-$posttype.php (single-espresso_events.php used only for EE events and wont exist by default, this allows you to take control over ALL EE events output by your theme)
single.php (Used by your theme to output pretty much all posts)
singlular.php (Basically a fallback for when ‘posts’ and ‘pages’ have exactly the same output, no need for 2 duplicate templates)
index.php (Fallback for everything)

You can also create custom templates (the $custom.php above) for specific post types, meaning you create a template and specify it is for espresso_events but the filename is my-custom-template.php. WordPress won’t look for that filename by default but because you’ve set it as a template for espresso_events, it shows on the Page Template dropdown when you edit the event, select it and its used in step 1 of the above.

I actually realise that I may be able to use the custom pages I already have and show and hide content using css and the post id for each event. That might be the simplest method for my purposes.

Sure, you can use other templates. The main think EE need is a call to the the_content() as that is how it automatically injects the event details but again you can also take over that output if preferred.

There’s just one thing I can’t work out how to do, though I would have thought that this would be somehow built in to EE.

That’s still a qty even if it’s just 1 as a radio button, but I see your point.

Is it the same for all of your events or do you need specific events to show ‘Qty’ and others to show ‘Select’?


Nick

May 15, 2020 at 5:36 am

Because I was asking about having different custom templates for different EE events, and I thought that, as you say, there is only one post type for EE events, I got confused as to how the method you were suggesting would give me different templates for different EE events. Maybe my initial post wasn’t clear, but perhaps you understand the confusion now?

It looks like I am actually working things out by creating multiple divs in the custom templates I have in my child theme folder and then hiding and showing these using css and the post IDs.

I do need specific events to show QTY (as multiple tickets can be selected) and others to show SELECT. After a bit of Googling I came up with this CSS solution:

th#quantity-#### {
  text-indent: -9999px;
  line-height: 0; 
}

th#quantity-####::after {
  content: "New text";
  text-indent: 0;
  display: block;
  line-height: initial;
}

Not sure if this will work in all browsers, and maybe there is a more elegant solution, but it works in my browser?: http://opendialogueapproach.co.uk/events/weekly-group/


Tony

  • Support Staff

May 15, 2020 at 6:14 am

You can use something like this:

https://gist.github.com/Pebblo/01368b45b94e43dbb10c69b3b245361c

Add a custom field on the event with the key ‘ee_custom_qty_text’ and whatever value you set within it will be used in place of the above.

Because you have the $event_id you could take that a little further, pul the event object and specifically check for $event->additional_limit() === 1 and then statically set the text to ‘Select’.

The support post ‘Is it possible to have multiple custom single event page layouts?’ 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