Jump to content

Get all pages with multiple categories as duplicates


strandoo
 Share

Recommended Posts

Hello ProcessPeople. I'm trying to get an xml file for a store locator-type map page. It works fine, but the client wants the icon colour to change depending on the location categories (which can be multiple categories). I've decide the easiest way to do this based on my existing javascript would be to just get multiple results in my xml file for those locations with multiple categories and let the js display. Like so:

'Location A' has 2 categories 'Residential, Health'
'Location B' has 2 categories 'Health, Education'
'Location C has 1 category 'Residential'

I'd like a selector which would produce this xml (sort of like the opposite of 'unique'):

<marker title="Location A" category="Residential" ... />
<marker title="Location A" category="Health" ... />
<marker title="Location B" category="Health" ... />
<marker title="Location B" category="Education" ... />
<marker title="Location C" category="Residential" ... />

Note that it doesn't matter if the result is 'category="Residential, Health"', as long as any location with 2 or more categories appears as a duplicate; I don't need to strip out the other categories since I'm using the first word of the category string to determine the colour of the marker.  I think I may need only one category returned, if possible. There are only 5 categories in total.

Any suggestions? I've tried searching through the forums and cheatsheet, but I don't really know the term for what I'm looking for. Non-unique? Thanks.

 

Link to comment
Share on other sites

Assuming the categories are assigned to locations by a Page Reference field named "categories":

$locations = $pages->find("template=location");
foreach($locations as $location) {
	foreach($location->categories as $category) {
		echo "<marker title='$location->title' category='$category->title'/>";
	}
}

 

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...