*

Ajit Sahane

  • ****
  • 147 posts
  • https://bestclassifiedsusa.com
Subcategory name only print in search.php
« 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.

*

MB Themes

Re: Subcategory name only print in search.php
« Reply #1 on: January 20, 2020, 04:15:41 PM »
@Ajit Sahane
That is not such easy. First you must get category hierarchy, i.e. using:
Code: [Select]
Category::newInstance()->toRootTree
or
Code: [Select]
Category::newInstance()->hierarchy
That will return array of all category IDs. Then for each ID you must get name using i.e.:
Code: [Select]
Category::newInstance()->findByPrimaryKey
GL!
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

Marked as best answer by frosticek on January 24, 2020, 01:46:01 PM
*

Ajit Sahane

  • ****
  • 147 posts
  • https://bestclassifiedsusa.com
Re: Subcategory name only print in search.php
« Reply #2 on: January 24, 2020, 12:07:25 PM »
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'];
    }
} ?>