Jump to content
strandoo

Get all pages with multiple categories as duplicates

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.

 

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

@Robin S Thanks, that's perfect. I can't believe it was that simple; I was definitely over-thinking it, trying things like append and add. Many thanks. - P

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...