taoguang Posted November 18, 2017 Posted November 18, 2017 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 Create the parent page /config/tags/ Create the tags template (no need to have a file, and only needs one field "title") 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?
kixe Posted November 18, 2017 Posted November 18, 2017 $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; } 1
Robin S Posted November 18, 2017 Posted November 18, 2017 @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.
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