Jump to content

How display tags's name


taoguang
 Share

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?

Link to comment
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
Link to comment
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.

 

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

×
×
  • Create New...