OS Property support center

How to display the name of the parent category?

  • Rashit
  • Topic Author
  • Offline
  • New Member
  • New Member
More
12 years 3 months ago - 12 years 3 months ago #23714 by Rashit
Hi !

There are 2 categories with subcategories. When I do advanced search in subcategories, it shows the name of subcategory only in results listing.

The code that doing this is

<?php echo $row->category_name?>

in results.html.tpl.php.

But I want to display full path to found properties (ex. category - subcategory) in results page.

How to "echo" parent category`s name before the subcategory name?

Please help.
Last edit: 12 years 3 months ago by Rashit.

Please Log in or Create an account to join the conversation.

More
12 years 3 months ago #23726 by Mr. Dam
Hi,
The solution is change :
<?php echo $row->category_name?>
to
<?php
if($row->category_id > 0){
$db = Jfactory::getDBO();
$db->setQuery("Select parent_id from #__osrs_categories where id = '$row->category_id'");
$parent_id = $db->loadResult();
if($parent_id > 0){
$db->setQuery("Select category_name from #__osrs_categories where id = '$parent_id'");
echo $db->loadResult()." - ";
}
echo $row->category_name;
}

?>


Good luck
Dam

Please Log in or Create an account to join the conversation.

  • Rashit
  • Topic Author
  • Offline
  • New Member
  • New Member
More
12 years 3 months ago #23788 by Rashit
Thank you very much. It works.

Please Log in or Create an account to join the conversation.

Moderators: Mr. DamNguyen Phu Quan