Advertisement:

Author Topic: Show SubCategory in search page  (Read 5398 times)

elena2

  • Newbie
  • *
  • Posts: 13
Show SubCategory in search page
« on: February 20, 2014, 08:53:06 pm »
hi
please help me!

how to  move SubCategory  in search page , like pictures :

 
« Last Edit: February 20, 2014, 09:05:12 pm by elena2 »

design

  • Hero Member
  • *****
  • Posts: 2619
  • Osclass 3.5 MAC/PC w/ Modern Browsers
Re: Show SubCategory in search page
« Reply #1 on: February 21, 2014, 12:31:58 am »
I have this, courtesy of teseo, but it is not styled at all - like your screen shot.


in search.php
where ever you want it...

Code: [Select]
<ul>
    <li><?php foreach(get_subcategories() as $subcat) { echo "<a href='".$subcat["url"]."'>".$subcat["s_name"]."</a> <span>(".get_category_num_items($subcat).")</span> | " ; } ?>
     </li>
</ul>

and in functions.php add these functions:

Code: [Select]
if( !function_exists('get_subcategories') ) {
         function get_subcategories( ) {
             $location = Rewrite::newInstance()->get_location() ;
             $section  = Rewrite::newInstance()->get_section() ;
           
             if ( $location != 'search' ) {
                 return false ;
             }
           
             $category_id = osc_search_category_id() ;
           
             if(count($category_id) > 1) {
                 return false ;
             }
           
             $category_id = (int) $category_id[0] ;
           
             $subCategories = Category::newInstance()->findSubcategories($category_id) ;
 
           
             foreach($subCategories as &$category) {
                 $category['url'] = get_category_url($category) ;
             }
           
             return $subCategories ;
         }
     }
      if ( !function_exists('get_category_url') ) {
         function get_category_url( $category ) {
             $path = '';
             if ( osc_rewrite_enabled() ) {
                if ($category != '') {
                    $category = Category::newInstance()->hierarchy($category['pk_i_id']) ;
                    $sanitized_category = "" ;
                    for ($i = count($category); $i > 0; $i--) {
                        $sanitized_category .= $category[$i - 1]['s_slug'] . '/' ;
                    }
                    $path = osc_base_url() . $sanitized_category ;
                }
            } else {
                $path = sprintf( osc_base_url(true) . '?page=search&sCategory=%d', $category['pk_i_id'] ) ;
            }
           
            return $path;
         }
     }
     
     if ( !function_exists('get_category_num_items') ) {
         function get_category_num_items( $category ) {
            $category_stats = CategoryStats::newInstance()->countItemsFromCategory($category['pk_i_id']) ;
           
            if( empty($category_stats) ) {
                return 0 ;
            }
           
            return $category_stats;
         }
     }

as I have it unstyled, I don't have it in columns I don't know how to put them in columns, nor do I have the time or let alone the space on my page to have wanted it.

calinbehtuk

  • Sr. Member
  • ****
  • Posts: 450
Re: Show SubCategory in search page
« Reply #2 on: February 22, 2014, 07:56:55 pm »
I did something like this. It worked, but I want something more. As each subcategories to have an image. On the main page I did this but in search page i fail to put images in subcategories. Can someone help me with an idea?

zelenika

  • Newbie
  • *
  • Posts: 8
Re: Show SubCategory in search page
« Reply #3 on: February 24, 2014, 07:09:46 am »
I have this, courtesy of teseo, but it is not styled at all - like your screen shot.


in search.php
where ever you want it...

Code: [Select]
<ul>
    <li><?php foreach(get_subcategories() as $subcat) { echo "<a href='".$subcat["url"]."'>".$subcat["s_name"]."</a> <span>(".get_category_num_items($subcat).")</span> | " ; } ?>
     </li>
</ul>

and in functions.php add these functions:

Code: [Select]
if( !function_exists('get_subcategories') ) {
         function get_subcategories( ) {
             $location = Rewrite::newInstance()->get_location() ;
             $section  = Rewrite::newInstance()->get_section() ;
           
             if ( $location != 'search' ) {
                 return false ;
             }
           
             $category_id = osc_search_category_id() ;
           
             if(count($category_id) > 1) {
                 return false ;
             }
           
             $category_id = (int) $category_id[0] ;
           
             $subCategories = Category::newInstance()->findSubcategories($category_id) ;
 
           
             foreach($subCategories as &$category) {
                 $category['url'] = get_category_url($category) ;
             }
           
             return $subCategories ;
         }
     }
      if ( !function_exists('get_category_url') ) {
         function get_category_url( $category ) {
             $path = '';
             if ( osc_rewrite_enabled() ) {
                if ($category != '') {
                    $category = Category::newInstance()->hierarchy($category['pk_i_id']) ;
                    $sanitized_category = "" ;
                    for ($i = count($category); $i > 0; $i--) {
                        $sanitized_category .= $category[$i - 1]['s_slug'] . '/' ;
                    }
                    $path = osc_base_url() . $sanitized_category ;
                }
            } else {
                $path = sprintf( osc_base_url(true) . '?page=search&sCategory=%d', $category['pk_i_id'] ) ;
            }
           
            return $path;
         }
     }
     
     if ( !function_exists('get_category_num_items') ) {
         function get_category_num_items( $category ) {
            $category_stats = CategoryStats::newInstance()->countItemsFromCategory($category['pk_i_id']) ;
           
            if( empty($category_stats) ) {
                return 0 ;
            }
           
            return $category_stats;
         }
     }

as I have it unstyled, I don't have it in columns I don't know how to put them in columns, nor do I have the time or let alone the space on my page to have wanted it.
I did everthing you said but nothing happend. No changes. Can you help me please?
Thanks

calinbehtuk

  • Sr. Member
  • ****
  • Posts: 450
Re: Show SubCategory in search page
« Reply #4 on: February 24, 2014, 11:26:30 am »
@zelenika
Check that all code to be copied correctly. I used this method and it works.

zelenika

  • Newbie
  • *
  • Posts: 8
Re: Show SubCategory in search page
« Reply #5 on: February 25, 2014, 09:19:23 am »
@zelenika
Check that all code to be copied correctly. I used this method and it works.
Thanks for your replay.
Well this is how my page looks like.



I like to see just categories, not ads.
And also after i click on category i am getting this error.

Warning: Cannot modify header information - headers already sent by (output started at /home/xxxxxxx/public_html/oc-includes/osclass/utils.php:1696) in /home/xxxxxx/public_html/oc-includes/osclass/utils.php on line 1699

Can you help me please?
Thanks

design

  • Hero Member
  • *****
  • Posts: 2619
  • Osclass 3.5 MAC/PC w/ Modern Browsers
Re: Show SubCategory in search page
« Reply #6 on: February 25, 2014, 09:28:45 am »
the last .php page you worked on has an extra blank line at the end of the file, just delete it-- the very last characters should be: ?>

as for removing the ads, you can just comment out that section of code(the loop. I would need to see the code to let you know what to comment out---what php page?


 

hidaiasoft

  • Newbie
  • *
  • Posts: 33
Re: Show SubCategory in search page
« Reply #7 on: April 06, 2014, 01:33:06 am »
how to get only 5 subcategories

blinkmeoff22

  • Newbie
  • *
  • Posts: 11
Re: Show SubCategory in search page
« Reply #8 on: December 30, 2014, 04:50:59 pm »
design, question to you, i did the same like u said, everything working, but when i press in search bar to show only listing with pictures, i get error...

Code: [Select]
Warning: Invalid argument supplied for foreach() in /home/m17984/public_html/live-amazing.com/oc-content/themes/moldova/search.php on line 192


design

  • Hero Member
  • *****
  • Posts: 2619
  • Osclass 3.5 MAC/PC w/ Modern Browsers
Re: Show SubCategory in search page
« Reply #9 on: December 31, 2014, 08:28:47 pm »
I didn't code that Teseo did. but for the time being you could remove that option- of looking with images?

maybe ask teseo, in a subject line, and include this thread??

monah

  • Full Member
  • ***
  • Posts: 223
Re: Show SubCategory in search page
« Reply #10 on: March 19, 2015, 12:13:58 pm »
1. and how to make that thought all ads from subcategory and the selected region?
2. and to consider only active ads?

monah

  • Full Member
  • ***
  • Posts: 223
Re: Show SubCategory in search page
« Reply #11 on: March 21, 2015, 12:25:45 pm »
up+++++ :)