A while ago I created an interactive map for my website using Ian Lunn’s BBC News Map, and custom fields to set the html for each area. It looks like this:-
I’m now trying to integrate this with a custom post type, the idea is that each map area would become a category with a list of posts in that category underneath (item 1, item 2 in the picture).
I’ve found examples of displaying a custom post type by category, but my template looks like this
<!--nw-->
<div id="nw" class="counties-container">
<h2>North West</h2>
<p class="nw-t"><?php if($data = get_post_meta($post->ID, 'North-West', true)) { echo $data; } ?></p>
</div>
<!--ne-->
<div id="ne" class="counties-container">
<h2>North East</h2>
<p class="nw-t"><?php if($data = get_post_meta($post->ID, 'North-East', true)) { echo $data; } ?></p>
</div>
Requiring custom code for each section. Is there an approach which would allow me to display the posts by category and keep the template code the way it is now, or should I rewrite the template so a single template can display all the areas.
Thanks in advance…
The easiest way would be to use a function which accepts a region taxonomy term as an argument, and outputs a list of posts with that term (i.e. ‘in that region’). So your template looks like:
I’m assuming that ‘nw’ is the term name (slug) of your North West region. Then you need to define the function (I’d recommend creating your own plug-in for this function, but if you must, you can use functions.php):
Below I assume your posts are of type ‘cpt_name’ and the region taxonomy name is ‘region’.
Please note this is untested.