Skip Navigation

[Resolved] Dynamic marker icon from taxonomy

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.

This thread is resolved. Here is a description of the problem and solution.

Problem: I have a View of posts that shows Markers on a Google Map. I would like to display a different Marker icon for each post depending on a taxonomy term. Each post will only have one term from this custom taxonomy.

Solution: You can use nested Views to show different icons based on the term.
- Create a new taxonomy View of categories (whatever taxonomy holds the terms museum, scenic road, etc).
- Add a Query Filter, filtered by taxonomy term, set by the current post in the loop. This means that the View will loop over all the terms associated with each POI post.
- In the Loop Output, insert a marker using the icon file based on the current term slug. So if you set up your icon file names to use a standard naming convention like "icon-poi-marker-termslug.png" you can just replace "termslug" each time with the corresponding term slug:

[wpv-layout-start]
    [wpv-items-found]
    <!-- wpv-loop-start -->
    <wpv-loop>
        [wpv-map-marker map_id="map-6" marker_id="marker-[wpv-taxonomy-id]" marker_icon="/wp-content/path/to/icon-poi-marker-[wpv-taxonomy-slug].png" marker_field="wpcf-address"][/wpv-map-marker]      
    </wpv-loop>
    <!-- wpv-loop-end -->
    [/wpv-items-found]
    [wpv-no-items-found][/wpv-no-items-found]
[wpv-layout-end]

- Modify the map ID, the marker_icon image filepath, and the marker_field slug as needed.
- Insert this new View inside the wpv-loop tags of your View of POIs.

Relevant Documentation:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-taxonomy-slug
https://toolset.com/documentation/user-guides/display-on-google-maps/#displaying-markers
https://toolset.com/documentation/user-guides/using-a-child-view-in-a-taxonomy-view-layout/

This support ticket is created 6 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 2 replies, has 2 voices.

Last updated by Christian Cox 6 years, 11 months ago.

Assisted by: Christian Cox.

Author
Posts
#613216

Hello,

I created a map and a loop that displays several markers on it from a child post type. I want the marker icon to reflect the taxonomy (only one for each child post).

For instance. I have a trip post type and a POI post type with an address field. The trip post type has a parent-child relation to POI (several POI for one trip). Each POI has a category (museum, scenic road, monument, ...) and i want that the marker on the map will have different icon according to the category.

Can i do that with toolset and how ? (Map is what i want, CurrentDisplay is what i have)
Regards

#613334
CurrentDisplay.png
Map.png

I have added the missing pictures (CurrentDisplay: what i have, Map:What i want)

#613529

You can use nested Views and conditional HTML to show different icons based on the term. Here's how I would do it:
- Create a new taxonomy View of categories (whatever taxonomy holds the terms museum, scenic road, etc).
- Add a Query Filter, filtered by taxonomy term, set by the current post in the loop. This means that the View will loop over all the terms associated with each POI post.
- In the Loop Output, insert a marker using the icon file based on the current term slug. So if you set up your icon file names to use a standard naming convention like "icon-poi-marker-termslug.png" you can just replace "termslug" each time with the corresponding term slug:

[wpv-layout-start]
	[wpv-items-found]
	<!-- wpv-loop-start -->
	<wpv-loop>
		[wpv-map-marker map_id="map-6" marker_id="marker-[wpv-taxonomy-id]" marker_icon="/wp-content/path/to/icon-poi-marker-[wpv-taxonomy-slug].png" marker_field="wpcf-address"][/wpv-map-marker]      
	</wpv-loop>
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found][/wpv-no-items-found]
[wpv-layout-end]

- Modify the map ID, the marker_icon image filepath, and the marker_field slug as needed.
- Insert this new View inside the wpv-loop tags of your View of POIs.

The forum ‘Types Community Support’ is closed to new topics and replies.