Osclass Support Forums
Osclass theme support => Beta Osclass Theme => Topic started by: Ajit Sahane on January 19, 2020, 05:14:57 PM
-
I want to show sub category name in search.php
active main category search page - no subcategory name print
active sub category search page - subcategory name print
1) <?php echo osc_item_category() ; ?> show perfect category name but this code not work in main category level.
2) osc_category_name($locale = "") - Gets the name of the current category - not work
any other code
xyz.com/for-sale - this case main category name is for sale then want <?php echo " for sale " ?>
xyz.com/for-sale/computer - this case want only sub-category ( computer ) name print in search.php --- HOW ..?
Pls help.
-
@Ajit Sahane
That is not such easy. First you must get category hierarchy, i.e. using:
Category::newInstance()->toRootTree
or
Category::newInstance()->hierarchy
That will return array of all category IDs. Then for each ID you must get name using i.e.:
Category::newInstance()->findByPrimaryKey
GL!
-
I can't modify code as per your above suggestions
but I found below code & its work for me.
<?php $dCategory = osc_search_category_id();
if(!empty($dCategory)) {
$cat = Category::newInstance()->findByPrimaryKey($dCategory[0]);
if(isset($cat['s_name'])) {
echo $cat['s_name'];
}
} ?>