suntrop Posted April 21, 2016 Share Posted April 21, 2016 The documentation is a little short on this topic … there seems to be only a getTag() and findTag() No way to check if there is a tag at all? The hasTag() method seems to be not allowed on image fields. I want to use an existing image field (something like WordPress’s featured image/post thumbnail) to gather images for a gallery as well. Problem is … <?php if(count($page->images)): ?> <img class="pull-right thumbnail" src="<?php echo $page->images->first->height(300)->url ?>" alt=""> <?php endif; ?> … there are thousands of pages/images without any tags and I can’t tag them all with »featured« to use them as now. Thus I have to tell my template to only use the first image without a tag to use as the featured image. Sounds complicated Hope you know what situation I am in Link to comment Share on other sites More sharing options...
Robin S Posted April 21, 2016 Share Posted April 21, 2016 $tagless_images = new WireArray(); foreach ($page->images as $image) { if(empty($image->tags)) { $tagless_images->add($image); } } Now $tagless_images is a WireArray of images on the page that have no tag. Edit: this is better... $tagless_images = $page->images->filter("tags=''"); 2 Link to comment Share on other sites More sharing options...
suntrop Posted April 22, 2016 Author Share Posted April 22, 2016 Thanks. It works The filter method looks far better, but I need the tagged photos later on this page.I tried this one <?php if(count( $page->images->has("tags=''") )): ?> but it is always true, even if there are only images with tags. Link to comment Share on other sites More sharing options...
Robin S Posted April 22, 2016 Share Posted April 22, 2016 The filter method looks far better, but I need the tagged photos later on this page. Not sure what you mean; $tagless_images are your images without tags, for images with tags you use: $mytag_images = $page->images->findTag('mytag'); I tried this one <?php if(count( $page->images->has("tags=''") )): ?> but it is always true, even if there are only images with tags. Count does not belong in your if expression: ->has() returns true or false so it doesn't make sense to count it. 2 Link to comment Share on other sites More sharing options...
suntrop Posted May 11, 2016 Author Share Posted May 11, 2016 Not sure what you mean; $tagless_images are your images without tags, for images with tags you use: filter() strips out all images without a tag. Those are not in $page->images after using filter() Link to comment Share on other sites More sharing options...
Robin S Posted May 11, 2016 Share Posted May 11, 2016 Okay, replace filter() with find(): $tagless_images = $page->images->find("tags=''"); 2 Link to comment Share on other sites More sharing options...
suntrop Posted May 11, 2016 Author Share Posted May 11, 2016 Well, that was simple Haven't thought of using find() behind images. Need to use PW more again. Thanks! 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