Jump to content

selector to find image description & tags


rushy
 Share

Recommended Posts

Hi

I have a number of pages with images and I'm having a problem selecting on the image descriptions. In the code snippet below, the I added images.description field to my selector and it does work in that I get the expected no. of matches. So findTag gets me a list of images matching the tags in the code, but if I swap that line for the commented line  $match->images->find      it does not work giving 0 results. 

There is findTag for tags but for description there is not a dedicated function, so I should use find. But what selector will give me a list of images matched by image description?

Many thanks.

if($q !== '') {
	$keywords = $sanitizer->selectorValue($q);
	$matches = $pages->find("template=album, title|summary|images.tags|images.description~=$keywords");		
		
	echo "<p>match count: $matches->count</p>";
	foreach($matches as $match){
		echo "<p>{$match->title}</p>";
		$i = $match->images->findTag($keywords);	
		//$i = $match->images->find("template=album, images.description~=$keywords"); GIVES ZERO MATCHES
		$j = count($i);
		echo "<p>No. of image matching: $j</p>";
			
		foreach($i as $img){
			echo "<img src='{$img->url}' alt='{$img->description}'>";
		}
	}			
}

 

Link to comment
Share on other sites

Looks to me (untested) like you shouldn't have images.description but rather description only in your selector, since you're already operating on the images themselves, and images themselves have no template (you have already limited the parent page in your $pages->find call to that).

$match->images->find("description~=$keywords");

should be enough.

  • Like 1
Link to comment
Share on other sites

6 hours ago, BitPoet said:

Looks to me (untested) like you shouldn't have images.description but rather description only in your selector, since you're already operating on the images themselves, and images themselves have no template (you have already limited the parent page in your $pages->find call to that).


$match->images->find("description~=$keywords");

should be enough.

Thank you. That works! But I now realise I need to iterate each album to build a list of tagged images matching. I wonder if there is a sub selector that can do that? Thanks again I can get on with it now 🙂

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.

  • Similar Content

    • By celfred
      Hello,
      I'm facing an issue trying to restrict access to a field so front-end edition is possible in an easy manner for the user. Let me explain :
      I have a field 'group' which is a Page list of group names. I want the user to be able to front-end edit a 'player' page in which this group field appears. I'd like the user to have a list of groups limited to his or her own groups (so he or she doesn't see all groups created by other users). In the back-end, I use this selector string : template=group, created_users_id=[user], sort=title This works great ! BUT here's my issue :
      If I back-end edit a 'player' page as 'Admin', the 'group' is empty (since admin is not the created-users-id and the group field is then empty... In other words, I must choose between all groups shown to all users (which may be scary for a user having only 2 or 3 groups whena list of 60 shows up) OR having a correct list for the front-end user, but empty for the back-end 'admin'.
      Can anyone think of another way I could get the expected result ? I have a feeling the simplest way would be to have a "Ignore for superusers" checkbox next to the 'selector string'. 
      Thanks !
    • By LMD
      I'm wondering if it is possible to add a label to the description input in image fields (in the admin).
      I'm using the module Image Extra, which has labels for each input, but I'd like to add a label to the default 'description' input too. The image below illustrates this:

       
      If there is no way (no hook?) then, I suppose I could just not use the default description and add a new description input with the Image Extra module.  But I thought I'd ask in case I (or others) ever want to do this without using the module (i.e. just the one input required).
      I'm using PW 3.0.98
      Thanks.
      ---
      FYI: yes, that is a cat and not a quilt -- this is on my local dev server and I don't have the actual photos yet! She is on a quilt, so it counts... technically.
       
    • By androbey
      I think it would be a great advantage for images to have an option to translate image tags, alongside the translatable description field (when using PWs language feature at all). 
      This feature could improve the multi language support in ProcessWire even further, thus the usability of it. 

      As a side effect that would also mean, that image tags could be easily used with the search engine, when dealing with a lot of images. 

       
    • By androbey
      Hello there,

      I was wondering if it's possible to somehow translate image tags. 

      Right now I have a page which outputs all images related to one tag in a single container (as there are many tags this results in various containers).

      Every container has a title (and id) with the tag string, but currently only in the language of the entered tags.

      Using the PW format inside the code like this does, of course, not work.. 
      _x($variable,'translated Tag') Is there a way to achieve this, without using workarounds (like extra fields)? 

      Cheers,
      Andreas
    • By sgt.blikey
      Has anyone had difficulty entering or editing image description text while on an iOS device?
      In my experience today the input box very occasionally accepts a tap to bring up the keyboard and cursor, but mostly behaves as if the field is uneditable.
      Standard text and textarea fields have been working as expected, as have text and textarea fields within repeaters.
      It's been a problem on a 2.5.28 and a 2.5.22 site.
      Nic
×
×
  • Create New...