Jump to content
Sign in to follow this  
Macrura

getting tags in use

Recommended Posts

Hi all, i think i need some help with this:

I have a field called Tags, which is a pageAutocomplete field, and allows the user to enter tags for a page;

Then on the template i have an isotope display which has a filter, using the tags;

Right now i'm just cycling through the tags (selector for template=tag) to create the list of filter links;

but is there a way to check that a given tag is actually in use, by a page, since right now if someone enters a tag and then deletes it, that tag is still a tag page, but if you click on that filter, no items are displayed...

TIA

Share this post


Link to post
Share on other sites

Maybe something like this could work:

$tags = $pages->find('template=tag');
foreach ($tags as $tag) {
  $c = $pages->count("tags={$tag}");
  if ($c == 0) //... this tag was not assigned to pages, so don't output it with your filter
}
  • Like 2

Share this post


Link to post
Share on other sites

Hi Wanze - many thanks - great and simple solution, nice thinking!

here is how i finally implemented:

<?php 
$tags = $pages->find("template=tag");                   
     foreach($tags as $tag) {                    
     $c = $pages->count("template=audio, tags={$tag}");
     if ($c == 0) continue;
 ?> 
//filter <li> markup here 
<?php } ?>
 
  • Like 2

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.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Sanyaissues
      After enable the Tags File Compiler module, echoing variables with brackets syntax doesn't work. I try something simple like {page.title} and is displayed like the tag isn't parsed:
      {page.title} This problem happens with PW 3.0.108, i have another installation with 3.0.82 and it works. Any Ideas? thanks.
    • By sww
      Hey there,
      is there really no way to turn the OR logic into an AND logic when selecting pages by (e.g.) tags?
      so instead of
       $pages->find("template=exhibitions, tags=foo|bar") something like
       $pages->find("template=exhibitions, tags=foo&&bar") so the pages needs to have all requested tags, not just any of them.
       
      Thanks,
      Stefan
    • By dimitrios
      Hello,
      I have created a field of type Page Reference and input field type Page Auto Complete, so that users of role 'writer' can add new tags to their articles. However, only a superuser can add new tags through the field, even though 'writer' roles have the permission to create  pages of template 'tag', and the permission to add children in the parent template. New tags in the Page Tree can be added normally. Is there something I am missing?

    • By louisstephens
      I have a "strange" issue with my dev set up, that I just noticed today. I set up an image field named "dev_gallery" and checked the "use tags" option when setting it up. I went to add a couple image to the field, and noticed that the tags option is not displaying at all for the image. Currently, the description field is the only current field on image edit. Have I missed a basic setting to enable this?
       
      I am currently using PW 3.0.62 as well.
    • By taoguang
      Hello, I follow this post to add tags
      Now in my template:
      $tags = explode(',', $page->tags); foreach ($tags as $tag) { $tag = trim($tag); echo $pages->find("tags=$tag"); } But I just display the tags ID, How to display tags page's title?
×
×
  • Create New...