Marcel Epp Posted October 16, 2017 Share Posted October 16, 2017 Hi, i'm trying to build a simple blog. Thanks to this forum it is working good. But i ran into a problem. How can i match my categories with the title? When i visit the page "Buchbinder" it should show me all pages that tagged with the category "Buchbinder" under "Neuigkeiten". How can i do that? My category page now looks like this: $blog_category = $pages->find("template=blog-entries"); foreach ($blog_category as $category) { echo "<a href='{$category->url}'>{$category->title}</a> "; } But how can i now say match the title from this site? thanks Marcel Link to comment Share on other sites More sharing options...
abdus Posted October 16, 2017 Share Posted October 16, 2017 Hmm. looking at your selector, you seem to be using `blog-entries` template for category pages. The exact solution will depend on how you configured your tagging system, but assuming you've used a Page Reference field called `category` limited to categories with `blog-entries` template, then you can use: // inside category template file // $page will point to a page with category template $categorized = $pages->find("template=blog-post, category=$page"); // ^ this will give you all pages with template blog-post whose category field include current page, (current category) // i.e. all posts under current category foreach($categorized as $post) { echo $post->title . '<br>'; } There's a tutorial by @kongondo which covers multiple scenarios and strategies for categorization, it's a must read for beginners. 3 1 Link to comment Share on other sites More sharing options...
Marcel Epp Posted October 17, 2017 Author Share Posted October 17, 2017 Hi abdus, thank you very much! the category=$page think was the missing piece! Now my category pages list the blog posts that assigned to that category. I have to tweak it for me cause my field has another name: <?php $blog_category = $pages->find("template=blog-entries, categories=$page"); foreach ($blog_category as $category) { echo "<a href='{$category->url}'>{$category->title}</a> "; } ?> Link to comment Share on other sites More sharing options...
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