Jump to content

[solved] Find Page that matches title


Marcel Epp
 Share

Recommended Posts

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?

59e511fe7bce5_Bildschirmfoto2017-10-16um22_09_13.png.ec04d145da9f41ac4173df81fbca67e4.png

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

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.

 

 

  • Like 3
  • Thanks 1
Link to comment
Share on other sites

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

  • Marcel Epp changed the title to [solved] Find Page that matches title

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...