pandaman Posted December 15, 2016 Share Posted December 15, 2016 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 More sharing options...
BitPoet Posted December 15, 2016 Share Posted December 15, 2016 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")); 2 Link to comment Share on other sites More sharing options...
pandaman Posted December 16, 2016 Author Share Posted December 16, 2016 Thank you. Just for the record, it's not "tag" but "tags". $tagsarray = array_unique($page->images->explode("tags")); Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now