How to find parent page name on search result
Permalink
Hello Concrete5 Masters,
I need a little help. I am creating a custom template on search block. What I want is show parent page name of the search result.
Looking at the search block view file, there is this:
Is there a way where I could do something like:
Any hint/direction will be highly appreciated.
I need a little help. I am creating a custom template on search block. What I want is show parent page name of the search result.
Looking at the search block view file, there is this:
<?php foreach($results as $r) { //Search result page names and urls etc here; $r->getPath(), $r->getName() etc }
Is there a way where I could do something like:
if($r->parentPageName()=="parent_page_name") { // Do some stuff here }
Any hint/direction will be highly appreciated.
Hi MoonGrab!
I tryed for hours to insert/edit your code in the view.php but it doesn't work.
Why is it possible to display the parent page "ID" but not it's name???
Best Mathias
I tryed for hours to insert/edit your code in the view.php but it doesn't work.
Why is it possible to display the parent page "ID" but not it's name???
Best Mathias
Dear friend,
finally I found a way to display the parents page name in my search results.
Put this anywhere you want:
<?php
$parent = page::getByID($page->getCollectionParentID());
print $parent->getCollectionName();
?>
Best Mathias
finally I found a way to display the parents page name in my search results.
Put this anywhere you want:
<?php
$parent = page::getByID($page->getCollectionParentID());
print $parent->getCollectionName();
?>
Best Mathias
THEN work with its parent.
Not tested but should work.
Put both code snippets inside your foreach cycle. Then you can do if($parentName == "blabla") ...
That's the whole c5 logic and most stuff is done this way.