Jump to content
taoguang

How display tags's name

Recommended Posts

Hello, I follow this post to add tags

Quote
  • Page Reference Field 
  • Parent page to hold the tags (for example: /config/tags/)
  • Template for the tags
  1. Create the parent page /config/tags/
  2. Create the tags template (no need to have a file, and only needs one field "title")
  3. Create a Page reference field. (called tags for this example)
    a. In the settings "Allow new pages to be created from this field"
    b. input field type: autocomplete, or whatever type works for what you are after.

Assign your "tags" field to templates where you want to allow tagging.

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?

Share this post


Link to post
Share on other sites

$pages->find() return a PageArray. Using echo PageArrays always return a string of the Page IDs separated by pipe "|" characters. Since you are looking for a single page you may want to use $pages->get(). To get the title of the page use $pages->get()->title.

$pages$tags = explode(',', $page->tags);
foreach ($tags as $tag) {
  $tag = trim($tag);
  echo $pages->get("tags=$tag")->title;
}

 

  • Like 1

Share this post


Link to post
Share on other sites

@taoguang, I think you might be mixing up two different approaches to tagging.

17 hours ago, taoguang said:

$tags = explode(',', $page->tags);

This looks like you have a text field with comma separated tags. But you don't need this if you are using pages for your tags - you can use a Page Reference field to add the tag pages directly. So like you quoted in your post:

17 hours ago, taoguang said:

Create a Page reference field. (called tags for this example)
a. In the settings "Allow new pages to be created from this field"
b. input field type: autocomplete, or whatever type works for what you are after.

 

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Robin S
      Displays image tags overlaid on the thumbnail using customisable colours. This makes it easier to see which images have which tags without needing to open the edit pane for individual images or changing to the list view.
      Screenshot

      Usage
      Enable tags for one or more image fields. Install the Image Thumbnail Tags module. Optionally configure colours for any of your tags.
       
      https://github.com/Toutouwai/ImageThumbnailTags
      https://modules.processwire.com/modules/image-thumbnail-tags/
    • By Andi
      Continuing my journey into PW hooks, I'm trying to find a way to retrieve all images from a page that explicitly *do not* have a certain tag (or tags) attached to them.
      Found this post from 2015
      But I'm wondering if there's a more elegant way to go about this.
      Let's say I have a multi-image field called "images_header" and instead of
      $page->images_header->findTag('mytag'); I would like to do this:
      $page->images_header->excludeTag('mytag'); So I'd be able to do
      // find images that don't have the tag "mytag" $images = $page->images_header->excludeTag('mytag'); // check if there's any images if (count($images)>0) { // do something.. } Would this be possible by hooking into Pagefiles somehow?
      There's this bit in /wire/core/Pagefiles.php Line 626 that I'd basically just need to reverse (or at least in my mind 😄 )
      public function findTag($tag) { $items = $this->makeNew(); foreach($this as $pagefile) { if($pagefile->hasTag($tag)) $items->add($pagefile); } return $items; } Any ideas on how this could be done in a graceful manner?
      Thanks in advance!
    • 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?

×
×
  • Create New...