Mijo Posted February 3, 2018 Posted February 3, 2018 Hello all, I'm trying to get all selected tags on my news list, so far when I go to specific news I see tags that I selected for that news, but when I'm on news list I see all tags that exists, not once that I selected. Tag field is page reference, I have selected Multiple pages (page array), input field type Amselect. My code so far looks like this: <?php $tags = $pages->get("/tag/")->find(); foreach($tags as $tag){ echo "<li><a href='{$tag->url}'>{$tag->title}</a></li>"; } ?> Can you help please with some advice how to get only selected tags on my news list?
adrian Posted February 4, 2018 Posted February 4, 2018 I think what you are looking for is: foreach($page->tags as $tag) { echo "<li><a href='{$tag->url}'>{$tag->title}</a></li>"; } I assume when you say "go to specific news" that means a page with a single news item.
Mijo Posted February 4, 2018 Author Posted February 4, 2018 3 hours ago, adrian said: I think what you are looking for is: foreach($page->tags as $tag) { echo "<li><a href='{$tag->url}'>{$tag->title}</a></li>"; } I assume when you say "go to specific news" that means a page with a single news item. Thanks for the reply but unfortunately it does not work, tags are not showing. With my code above I achieve that tags (selected tags for news item) showing on single news, for example test 1, test 2 but when I am on to news list I see all tags that I have created.
PWaddict Posted February 4, 2018 Posted February 4, 2018 @Mijo Try this: //Grabbing the news list $posts = $page->children("limit=10"); //Rendering each news post foreach($posts as $post) { echo "Lorem Ipsum..."; //Rendering selected tags inside each post foreach($post->tags as $tag) { echo "<li><a href='{$tag->url}'>{$tag->title}</a></li>"; } } 1 1
Mijo Posted February 5, 2018 Author Posted February 5, 2018 19 hours ago, PWaddict said: @Mijo Try this: //Grabbing the news list $posts = $page->children("limit=10"); //Rendering each news post foreach($posts as $post) { echo "Lorem Ipsum..."; //Rendering selected tags inside each post foreach($post->tags as $tag) { echo "<li><a href='{$tag->url}'>{$tag->title}</a></li>"; } } Thank you very much!
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