I have created an events custom post type archive by custom date field and completed all related pages successfully.
It has :
Archive page in the format : http://www.example.com/events/
Archive by month (event date and not published date) list and having proper url structuring like: http://www.example.com/2015/11/events/
You can check this question which I asked recently to understand my approach towards creating the events which is archived by custom date field.
I created events archive page using
get_template_part('content', get_post_type()); in archive.php page.
So the archive page name is
Now I am not able to find a clean solution to make a gallery page for events which has:
- Images and name of the events listed by month.
- Archive list with some proper url structuring like : www.example.com/2015/11/gallery/events , www.example.com/2015/10/gallery/csrevents
Suppose there are 2 types of events
- events - /gallery/events
- csrevents -/gallery/csrevents And a common url /gallery
How can I route all three url's to same template file and then conditionally load the data based on url
I thought of following approach but I am not sure if it will be the correct way:
To create a page programmatically using
wp_insert_postand setting the page template to
template-gallery.phpand setting the slug as
WP_Queryto get events post type by month in this page.
Changing the url format to www.example.com/2015/11/gallery/events/in this plugin when the page name is template-gallery.php
pre-get-postto highjack the url www.example.com/2015/11/gallery/events to get the month and year and setting post type as events. This shall return the posts for this month and year.
The main problem here is that I am trying to have 2 archive pages for same post type and this is making the process dirty.
I would like to know if there is a better way of doing this.