0

I'm still quite new to Wordpress - after a pointer or two.

I've created a archive page for a custom post type of 'property'. This is set-up, working from an admin point of view, and I have a listing/index page showing the content created using a template I've themed called 'archive-property.php'.

While this archive template shows a listing page of these posts, I also need a separate view which shows the same posts plotted on a google map.

I'm quite familiar with setting up google maps - but wondering how I route a URL to this template in wordpress?

So the ideal aim is that the /property/ carries on serving content using the archive-property.php template.

Then there would be a /property/map/ page which would need to load from a different template file - something like archive-property-map.php...

How do I tell wordpress that a request for this 2nd URL should use that template?

| improve this question | | | | |
1

This is not as straight forward as you would think and can give you some headaches. You will need to make use of rewrite rules to rewrite your desired URL.

The real problem here is that property/map/ will be treated as a single post, which will 404 because a post with that name does not exist. You will need to tell Wordpress that whenever it encounters this specifc URL, it must treat it in the same way as a normal custom post type archive page. I can't help you with rewrite rules as frankly, that is a specialized section that I still need to explore and get to understand.

Just to give you some idea, you can go and check out this post I have recently done. You must also check out the linked question in my answer and check out the answer from @Milo. You will need to do the same type of thing, rewrite your URL to the home page with your custom post type, and then set your conditionals accordingly.

Once you get that part going, then it is easy. You can simply then just get the URL and if it matches your URL, you can use the template_include filter to tell Wordpress to use your custom template.

I believe that the linked post will solve almost all of your issues.

| improve this answer | | | | |
1

You can only create a single archive page per post type/category/tag or any other grouping. The best way will be to create a page template maybe property-map.php for your maps page.

| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.