Jump to content

Get all unique images tags


pandaman
 Share

Recommended Posts

Hi! I'ts my first post here and i say hello to everyone. I've just started learning Processwire, but i love it so much!
It's so simple (and deep), that after a lot of years on Wordpress, it seems incredible to me to create great sites without a headache!

By the way, i'm creating a gallery page in my first processwire site, using the default images field.
I activated the tags on that field (tag for the images, not for the field), to have a simple taxonomy.
I need to read all those tags once (for that page), and i wrote something like

foreach($page->images as $tag) { 
$tagsarray[] = $tag->tags;
}
				
$tagsarray = array_unique($tagsarray);
foreach($tagsarray as $tag) { 
echo "<div class='filter-item wow fadeInUp' data-wow-delay='.1s' data-filter='{$tag}'>{$tag}</div>"; 
}

It works, but i bet there is a shorter API trick. Am i right?
I read something about  a->unique() function...

Link to comment
Share on other sites

WireArray's unique method is not what you're looking for, it removes duplicate entries from a WireArray like your images field, and the image list is already unique. But you could shorten the filling of your tags array (the internal steps are basically the same as what your code does):

$tagsarray = array_unique($page->images->explode("tag"));

 

  • 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...