Advertisement:

Author Topic: How to limit number of sub categories to 5 on homepage?  (Read 11507 times)

rahulk

  • Full Member
  • ***
  • Posts: 132
  • What we face is destiny, how we face is free will.
How to limit number of sub categories to 5 on homepage?
« on: October 04, 2013, 10:54:28 am »
Hello Friends

I am using osclass 3.2.1 with default bender theme, my query is how to limit number of subcategories to 5 on homepage.

Thanks!

design

  • Hero Member
  • *****
  • Posts: 2619
  • Osclass 3.5 MAC/PC w/ Modern Browsers
Re: How to limit number of sub categories to 5 on homepage?
« Reply #1 on: October 04, 2013, 11:02:16 pm »
The only resolve I've seen for this was putting it into an iframe. but there might be a better resolution...

marylooo

  • Newbie
  • *
  • Posts: 16
Re: How to limit number of sub categories to 5 on homepage?
« Reply #2 on: October 05, 2013, 12:27:46 pm »
The file oc-content\themes\bender\functions.php contains a function named bender_draw_categories_list().

I recommend you look at line 187, which is the beginning of a while() loop that I think iterates through the subcategories of the current category. You might be able to add a variable to the code (e.g. $num_subcats_displayed_so_far), that counts the number of subcategories displayed so far, and some logic (i.e. if $num_subcats... == 5 ) that causes PHP to break out of the while loop after displaying the 5th subcategory for a given category.

Here's what I mean (I added the lines with the comments after them).

Code: [Select]
<ul>
         <?php $max_subcats_to_show 5// define some maximum number of subcategories to show per category ?>
<?php $num_subcats_shown 0// restart counter for the new category ?>
<?php while ( osc_has_subcategories() ) { ?>

<li>
<?php if( osc_category_total_items() > ) { ?><a class="category <?php echo osc_category_slug() ; ?>" href="<?php echo osc_search_category_url() ; ?>"><?php echo osc_category_name() ; ?></a> <span>(<?php echo osc_category_total_items() ; ?>)</span>
<?php } else { ?><span><?php echo osc_category_name() ; ?> (<?php echo osc_category_total_items() ; ?>)</span></li>
<?php ?>

<?php $num_subcats_shown++; // increment counter because just displayed another subcategory ?>
<?php if( $num_subcats_shown >= $max_subcats_to_show ) break; // break out of while loop if displayed enough subcategories ?>

<?php ?>
</ul>

Does it do what you want?

I would like for the Blender theme to include this in the admin panel--in other words, to have an option where we can enter the max number of subcategories we want displayed per parent category. Then they can use that option (if defined) inside this function.
« Last Edit: October 05, 2013, 12:39:20 pm by marylooo »

rahulk

  • Full Member
  • ***
  • Posts: 132
  • What we face is destiny, how we face is free will.
Re: How to limit number of sub categories to 5 on homepage?
« Reply #3 on: October 05, 2013, 02:17:52 pm »
Thank you marylooo for your efforts but your code does not work properly

1. it shows 5 subcategories of 1st category

2. does not show any subcategory of 2nd main category

3. does not show (more..) as a link to all subcategories of that main category.

 

strata

  • Sr. Member
  • ****
  • Posts: 411
  • Always good, always...
Re: How to limit number of sub categories to 5 on homepage?
« Reply #4 on: October 05, 2013, 02:30:03 pm »
You need  to limit it by Javascript

rahulk

  • Full Member
  • ***
  • Posts: 132
  • What we face is destiny, how we face is free will.
Re: How to limit number of sub categories to 5 on homepage?
« Reply #5 on: October 14, 2013, 03:36:29 pm »
Thanks strata!

I was on vacation. Can you guide me further, I really need to limit subcategories to 5 and (more...) as a link to all subcategories of particular parent category. Using default bender theme with 3.2.1

Thanks!

strata

  • Sr. Member
  • ****
  • Posts: 411
  • Always good, always...
Re: How to limit number of sub categories to 5 on homepage?
« Reply #6 on: October 14, 2013, 04:40:14 pm »
Maybe this code, please put this code on your global.js files under js folder :
Code: [Select]
$(document).ready(function(){
    $('.r-list li ul').find('li:gt(3)').addClass('toggletr').hide()
    .end().append(
      $('<ul><li class="show_more_btn"><a>More »</a></li></ul>').click(function(){
          $(this).siblings('.toggletr').toggle();
          if($(this).hasClass('expanded')){
              $(this).html('<a>More »</a>');
              $(this).removeClass('expanded');
          } else{
              $(this).html("<a>Less «</a>");
              $(this).addClass('expanded');
          }
     })
    );
});


design

  • Hero Member
  • *****
  • Posts: 2619
  • Osclass 3.5 MAC/PC w/ Modern Browsers
Re: How to limit number of sub categories to 5 on homepage?
« Reply #7 on: October 14, 2013, 08:41:55 pm »
this is what I use. in bender 3.2.1 in functions.php, I'm trying to limit the amount of core files I change.
change the 8 to a 5 (or how ever many you want to show) in this code the count shows before, please change to your preference.

<?php if ( osc_count_subcategories() > 0 ) { ?>
    <ul>
      <?php $tic = 0; while ( osc_has_subcategories() && $tic < 8) { ?>
      <li><span><?php if(osc_category_total_items()>0){ echo '('.osc_category_total_items().')';} ?></span> <a class="category <?php echo osc_category_slug() ; ?>" href="<?php echo osc_search_category_url() ; ?>"><?php echo osc_category_name() ; ?></a> </li>
      <?php $tic++;} ?>
      <?php View::newInstance()->_erase('subcategories') ; ?>
    <a href="<?php echo osc_search_category_url() ; ?>"> view more...</a></ul>
    <?php } ?>
  </li>
</ul>
<?php
                $i++;
            }
            echo '</div>';
        ?>
« Last Edit: October 14, 2013, 08:47:23 pm by design »

Hello

  • Full Member
  • ***
  • Posts: 174
Re: How to limit number of sub categories to 5 on homepage?
« Reply #8 on: October 16, 2013, 12:36:35 pm »
i want a boarder around categories

design

  • Hero Member
  • *****
  • Posts: 2619
  • Osclass 3.5 MAC/PC w/ Modern Browsers
Re: How to limit number of sub categories to 5 on homepage?
« Reply #9 on: October 16, 2013, 06:33:30 pm »
to get borders you will have to style it in your css.
use your browsers "developer tools" to find out which class needs to be styled. this would be true for all themes.

SmaRTeY

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2519
Re: How to limit number of sub categories to 5 on homepage?
« Reply #10 on: January 15, 2014, 01:41:11 pm »
Hi design,

what happens using your code sample if 'Read more' if pressed?
I can see the osc_search_category_url call and I have looked it up in the docs but I am not certain what exactly happens. Is the category being expanded on the same screen or is there a redirect to ..... ?  ::)

I would prefer the 'More' option as well though with the subs being expanded down to see all other cats after keypress on more.


Thanks,
Eric

design

  • Hero Member
  • *****
  • Posts: 2619
  • Osclass 3.5 MAC/PC w/ Modern Browsers
Re: How to limit number of sub categories to 5 on homepage?
« Reply #11 on: January 15, 2014, 06:30:18 pm »
that is a good idea, and I see your point. this is what I'm going to do about that. the home page will remain as is and the view more will go the the search page as is. but once I start getting ads, I'd like to have the rest of the subcategories listed in short columns at the top of the search page. as I have a lot maybe 4 columns 8 or 9 rows -+. I will cross that bridge when I get to it.

 I won't "view more" with a drop down because of devices, there are just to many and my css is already 4k lines. (yes, some dups)

SmaRTeY

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2519
Re: How to limit number of sub categories to 5 on homepage?
« Reply #12 on: January 16, 2014, 02:27:19 am »
4K...wow :)
Making subcats in columns above search sounds interesting as well, I am Always open for good suggestions.
The other day somebody was asking about an intermediate page showing the subs per sub. For now, knowing that OsClass is focussed on two cats, that will have to wait I guess but once the nr of categories get really big it would be an interesting extra feature for people who use the ad site(s) as an online 'mall'....  8)

Ashok Bhamla

  • Full Member
  • ***
  • Posts: 126
  • Just ask me
Re: How to limit number of sub categories to 5 on homepage?
« Reply #13 on: April 08, 2016, 09:40:10 pm »
this is what I use. in bender 3.2.1 in functions.php, I'm trying to limit the amount of core files I change.
change the 8 to a 5 (or how ever many you want to show) in this code the count shows before, please change to your preference.

<?php if ( osc_count_subcategories() > 0 ) { ?>
    <ul>
      <?php $tic = 0; while ( osc_has_subcategories() && $tic < 8) { ?>
      <li><span><?php if(osc_category_total_items()>0){ echo '('.osc_category_total_items().')';} ?></span> <a class="category <?php echo osc_category_slug() ; ?>" href="<?php echo osc_search_category_url() ; ?>"><?php echo osc_category_name() ; ?></a> </li>
      <?php $tic++;} ?>
      <?php View::newInstance()->_erase('subcategories') ; ?>
    <a href="<?php echo osc_search_category_url() ; ?>"> view more...</a></ul>
    <?php } ?>
  </li>
</ul>
<?php
                $i++;
            }
            echo '</div>';
        ?>
i have done same thing but mine last parent category not display.

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: How to limit number of sub categories to 5 on homepage?
« Reply #14 on: April 08, 2016, 11:57:45 pm »
Hi,

For latest Bender 3.1.4, locate this block in bender/functions.php:

Code: [Select]
                 <?php if ( osc_count_subcategories() > ) { ?>
                   <ul>
                         <?php while ( osc_has_subcategories() ) { ?>
                             <li>
                             <?php if( osc_category_total_items() > ) { ?>
                                 <a class="category sub-category <?php echo osc_category_slug() ; ?>" href="<?php echo osc_search_category_url() ; ?>"><?php echo osc_category_name() ; ?></a> <span>(<?php echo osc_category_total_items() ; ?>)</span>
                             <?php } else { ?>
                                 <a class="category sub-category <?php echo osc_category_slug() ; ?>" href="#"><?php echo osc_category_name() ; ?></a> <span>(<?php echo osc_category_total_items() ; ?>)</span>
                             <?php ?>
                             </li>
                         <?php ?>
                   </ul>

Replace with:

Code: [Select]
                 <?php if ( osc_count_subcategories() > ) { ?>
                 <ul>
                     <?php $tic 0; while ( osc_has_subcategories() && $tic 8) { ?>
                     <li><span><?php if(osc_category_total_items()>0){ echo '('.osc_category_total_items().')';} ?></span> <a class="category <?php echo osc_category_slug() ; ?>" href="<?php echo osc_search_category_url() ; ?>"><?php echo osc_category_name() ; ?></a> </li>
                     <?php $tic++;} ?>
                     <?php View::newInstance()->_erase('subcategories') ; ?>
                     <a href="<?php echo osc_search_category_url() ; ?>"> view more...</a></ul>
                 <?php ?>
             </li>
        </ul>

Regards