Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

WordPress plugin: events

So I am working on a website for my martial arts school. I am doing it pro bono to pad my portfolio and I know Master Sawyer can't really sink money into a website. I've tried 'The Calendar' by tribes, I've tried All-in-One-Event-Calendar. I just can't seem to get it right.

on the presentation level I need to be able to have a widget that will display X amount of upcoming events of a certain type/category with in a given time frame say for example show the next 4 upcoming events in the categories 'tournaments', 'test', and 'fundraisers' if any events are with in 30 days. Not display regularly scheduled classes unless class is canceled in which case display above the 'upcoming events' something like "class canceled due to weather (today's date)".

I also need to have an agenda for the main "schedule" page that show repeating events like in categories "classes", "tests" that display a 'week view' so if a user clicks on the schedule page they see that Monday, Wednesday, and Friday this week we have class from 600p - 800pm but next week we have classes Monday, Wednesday, and Friday as well as a test on Saturday at 9am.

On the back-end extras like "venues", "organizers", "importing a CSV" are nice but for the most part its always going to be the same couple organizers, at the same two or three venues. It would be sweet to have the calendar sync with our social media like facebook and google+ not just posting a message to them but actually changing our 'business' hours to reflect a closure etc.

I'd like to be able to template the widget with something like:

h4<?php the_event_title(); ?>/h4 p<?php the_event_time('date') ?>/p img src="<?php the_event_image(); ?>" / p<?php the_event_location(); ?>/p a href="<?php the_event(); ?>" View Event Details /a

for example

6 Answers

Gareth Borcherds
Gareth Borcherds
9,372 Points

So, The Calendar by tribes simply uses a custom post type to create it's events in the database and uses custom meta fields for event data. You can get all the details you need by building a WP_query or some variation of the post loop. It would require quite a bit of custom code, but the steps I would do to create the widget would be:

  1. Register the widget
  2. Create the code for the widget that uses some variation of the wp query or post loop
  3. Put the widget in your site

I'd read up on http://codex.wordpress.org/Class_Reference/WP_Query as this would allow you to pull the data you want and use the functions you are looking for.

That's pretty much where I saw this going. The only downfall is I'm not sure what calls the tribes calendar make you know like the_plugin_field();

Gareth Borcherds
Gareth Borcherds
9,372 Points

I wouldn't worry about how the plugin does it. In the end, the data is stored in a database and the data is accessed via queries. All those functions simply make queries on the database. I'm all about the path of least resistance, and that path is to ignore what the plugin does and just use the easiest method to pull the data and display it.

Right but how to I know exactly what call to make to read that particular data? I have to know the specific tables and such no? WordPress codex does a good job of telling you how to navigate around WordPress core itself.

Gareth Borcherds
Gareth Borcherds
9,372 Points

You can figure that out one of two ways. 1) by browsing the plugin files and templates created by the authors 2) browse the database and see where the store stuff.

This plugin stores everything in core tables. The post are in posts as a custom post type. The start date and event times are all stored in post_meta table. You just need to know what the meta_key value is so you can get_post_meta and then use that to pull the stuff using the core wordpress functions.

You might also browse the plugin author's site for any documentation that might be there.

Just an update acf has Short code so I'm able to add my short code into the content field and call functions inside of functions. Not ideal but it works.