Advertisement:

Author Topic: Number of ads in sub categories (Solved)  (Read 2327 times)

Pathfinder

  • Newbie
  • *
  • Posts: 18
Number of ads in sub categories (Solved)
« on: January 30, 2014, 11:38:53 pm »
I am in the early stages of development of my site and wondered if anybody can help with this;

Is there any change I can make so that the number of ads in a sub category shows in the drop down on the main page?

My site is www.caravancleaningservices.co.uk - The test ads posted are all in the 'Haven' category.

I am using:
Version 3.3.2

Theme  = Twitter

Plug ins Installed;
Ads4osclass
Cookie warning
Google maps
Qr codes
Site map generator
Social bookmarks
 
« Last Edit: February 03, 2014, 10:34:39 pm by Pathfinder »

aide2001

  • Guest
Re: Number of ads in sub categories
« Reply #1 on: January 30, 2014, 11:43:38 pm »
do you mean something like the original theme?
say Parkdean (23)
 sub cat Cherry Tree (4) etc



Pathfinder

  • Newbie
  • *
  • Posts: 18
Re: Number of ads in sub categories
« Reply #2 on: January 31, 2014, 02:55:04 am »
Yes, that's exactly what I need.

strata

  • Sr. Member
  • ****
  • Posts: 411
  • Always good, always...
Re: Number of ads in sub categories
« Reply #3 on: January 31, 2014, 11:59:58 am »
Are you have try to add <?php echo osc_category_total_items() ; ?> functions ?

Pathfinder

  • Newbie
  • *
  • Posts: 18
Re: Number of ads in sub categories
« Reply #4 on: January 31, 2014, 12:27:03 pm »
OK, thanks, but I'm very new to this, so where should I add that line?

strata

  • Sr. Member
  • ****
  • Posts: 411
  • Always good, always...
Re: Number of ads in sub categories
« Reply #5 on: January 31, 2014, 01:23:30 pm »
Open your theme folder > functions.php and find this line
Code: [Select]
        if( osc_count_categories() > 0 ) {
            echo '<select name="sCategory" data-placeholder="' . __('Select a category...', 'twitter') . '" style="width: auto;" class="chosen-select">' ;
            echo '<option></option>' ;
            while( osc_has_categories() ) {
                echo '<option value="' . osc_category_id() . '">' . osc_category_name() . '</option>' ;
                if( osc_count_subcategories() > 0 ) {
                    while( osc_has_subcategories() ) {
                        echo '<option class="level-1" value="' . osc_category_name() . '">' . osc_category_name() . '</option>' ;
                    }
                }
            }
            echo '</select>' ;
        }

Change with this :
Code: [Select]
    function chosen_select_standard() {
        View::newInstance()->_exportVariableToView('categories', Category::newInstance()->toTree() ) ;

        if( osc_count_categories() > 0 ) {
            echo '<select name="sCategory" data-placeholder="' . __('Select a category...', 'twitter') . '" style="width: auto;" class="chosen-select">' ;
            echo '<option></option>' ;
            while( osc_has_categories() ) {
                echo '<option value="' . osc_category_id() . '">' . osc_category_name() . '<span> '. osc_category_total_items().'</span>'.'</option>' ;
                if( osc_count_subcategories() > 0 ) {
                    while( osc_has_subcategories() ) {
                        echo '<option class="level-1" value="' . osc_category_name() . '">' . osc_category_name() . '</option>' ;
                    }
                }
            }
            echo '</select>' ;
        }

        View::newInstance()->_erase('categories') ;
    }
hope it work

Pathfinder

  • Newbie
  • *
  • Posts: 18
Re: Number of ads in sub categories
« Reply #6 on: January 31, 2014, 03:32:59 pm »
Thanks again.

I have changed the lines you suggested, but unfortunately there is no change.

I have left the new lines in place. Can you suggest anything else?

aide2001

  • Guest
Re: Number of ads in sub categories
« Reply #7 on: January 31, 2014, 07:47:29 pm »
Maybe try the <?php echo osc_category_total_items() ; ?> in the header or main where ever you have the menu system. Something like <?php echo_osc_catergories;?> <?php echo osc_category_total_items() ; ?>
I'm not an expert on php im only guessing, if it doesnt work take it back out

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: Number of ads in sub categories
« Reply #8 on: January 31, 2014, 08:30:48 pm »
Hi,

Code: [Select]
while( osc_has_categories() ) {
                echo '<option value="' . osc_category_id() . '">' . osc_category_name() .'</option>' ;
                if( osc_count_subcategories() > 0 ) {
                    while( osc_has_subcategories() ) {
                        echo '<option class="level-1" value="' . osc_category_name() . '">' . osc_category_name() . '&nbsp;(' . osc_category_total_items() . ')' . '</option>' ;
                    }

@strata, you put your osc_category_total_items() accompanying parent category (no items unless expressly authorized on the admin dashboard) not subcategories. And I think that HTML won't allow to embed elements inside a select option (<span>), ugly but unavoidable without a lot of Javascript tricks.

Regards

Pathfinder

  • Newbie
  • *
  • Posts: 18
Re: Number of ads in sub categories
« Reply #9 on: January 31, 2014, 10:46:30 pm »
Guys, Thanks for you help it is appreciated, however, so far I have not managed to get anything to work  :(

Hi,

Code: [Select]
while( osc_has_categories() ) {
                echo '<option value="' . osc_category_id() . '">' . osc_category_name() .'</option>' ;
                if( osc_count_subcategories() > 0 ) {
                    while( osc_has_subcategories() ) {
                        echo '<option class="level-1" value="' . osc_category_name() . '">' . osc_category_name() . '&nbsp;(' . osc_category_total_items() . ')' . '</option>' ;
                    }

@strata, you put your osc_category_total_items() accompanying parent category (no items unless expressly authorized on the admin dashboard) not subcategories. And I think that HTML won't allow to embed elements inside a select option (<span>), ugly but unavoidable without a lot of Javascript tricks.

Regards

@teseo
Is this code to be used in addition to @strata's code or as a replacement of all or part of it?

As I've said I'm very new to this and so not really sure.

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: Number of ads in sub categories
« Reply #10 on: January 31, 2014, 11:22:19 pm »
You have to replace this:


Code: [Select]
            while( osc_has_categories() ) {
                echo '<option value="' . osc_category_id() . '">' . osc_category_name() . '</option>' ;
                if( osc_count_subcategories() > 0 ) {
                    while( osc_has_subcategories() ) {
                        echo '<option class="level-1" value="' . osc_category_name() . '">' . osc_category_name() . '</option>' ;
                    }

with the code in my previous mesage (I'll repeat it and mark in green what's the difference):

Quote
while( osc_has_categories() ) {
                echo '<option value="' . osc_category_id() . '">' . osc_category_name() .'</option>' ;
                if( osc_count_subcategories() > 0 ) {
                    while( osc_has_subcategories() ) {
                        echo '<option class="level-1" value="' . osc_category_name() . '">' . osc_category_name() . '&nbsp;(' . osc_category_total_items() . ')' . '</option>' ;
                    }

Regards

Pathfinder

  • Newbie
  • *
  • Posts: 18
Re: Number of ads in sub categories
« Reply #11 on: February 01, 2014, 03:26:07 am »
Ok Guys, this is what I've done;

functions.php

I have changed lines 3 - 18

Code: [Select]
    function chosen_select_standard() {
        View::newInstance()->_exportVariableToView('categories', Category::newInstance()->toTree() ) ;

 if( osc_count_categories() > 0 ) {
            echo '<select name="sCategory" data-placeholder="' . __('Select a category...', 'twitter') . '" style="width: auto;" class="chosen-select">' ;
            echo '<option></option>' ;
            while( osc_has_categories() ) {
                echo '<option value="' . osc_category_id() . '">' . osc_category_name() . '</option>' ;
                if( osc_count_subcategories() > 0 ) {
                    while( osc_has_subcategories() ) {
                        echo '<option class="level-1" value="' . osc_category_name() . '">' . osc_category_name() . '</option>' ;
                    }
                }
            }
            echo '</select>' ;
        }

   

to this
   
Code: [Select]
function chosen_select_standard() {
        View::newInstance()->_exportVariableToView('categories', Category::newInstance()->toTree() ) ;

        if( osc_count_categories() > 0 ) {
            echo '<select name="sCategory" data-placeholder="' . __('Select a category...', 'twitter') . '" style="width: auto;" class="chosen-select">' ;
            echo '<option></option>' ;
            while( osc_has_categories() ) {
                echo '<option value="' . osc_category_id() . '">' . osc_category_name() .'</option>' ;
                if( osc_count_subcategories() > 0 ) {
                    while( osc_has_subcategories() ) {
                        echo '<option class="level-1" value="' . osc_category_name() . '">' . osc_category_name() . '&nbsp;(' . osc_category_total_items() . ')' . '</option>' ;
                    }
                }
            }
            echo '</select>' ;
        }
.............................

Header.php

Line 55

Code: [Select]
<a href="<?php echo osc_search_category_url() ; ?>" <?php if ( osc_count_subcategories() > ) { ?>class="menu"<?php ?>><?php View::newInstance()->_erase('subcategories'); echo osc_category_name() ; ?></a>


I have added

Code: [Select]
<?php echo_osc_catergories;?> <?php echo osc_category_total_items() ; ?>
To make

Code: [Select]
<a href="<?php echo osc_search_category_url() ; ?>" <?php if ( osc_count_subcategories() > ) { ?>class="menu"<?php ?>> <?php echo_osc_catergories;?> <?php echo osc_category_total_items() ; ?> <?php View::newInstance()->_erase('subcategories'); echo osc_category_name() ; ?></a>

I now have numbers next to Category Names, but the count is wrong and there are no numbers next to sub categories in drop down.

We seem to be getting there, but not quite made it yet :( any more ideas guys?

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: Number of ads in sub categories
« Reply #12 on: February 01, 2014, 09:05:25 pm »
Code: [Select]
<?php echo_osc_catergories;?> <?php echo osc_category_total_items() ; ?>

First, you have to be more careful. It's not only that your php syntax is totally wrong, is that you wrote "catergories". :)

The function chosen_select_standard() is right, if you see wrong numbers might be because your stats are not being updated by the Osclass cron job. Check in your Admin Dashboard / Settings, "Automatic cron process", that should be checked. To update the stats manually go to Show More menu / Tools / Category Stats

And the header part, you changed the wrong line. The line 55 is for parent categories, for subcategories replace line 59:

Code: [Select]
<li class="<?php echo osc_category_slug() ; ?>"><a href="<?php echo osc_search_category_url() ; ?>"><?php echo osc_category_name() ; ?></a></li>
with:

Code: [Select]
<li class="<?php echo osc_category_slug() ; ?>"><a href="<?php echo osc_search_category_url() ; ?>"><?php echo osc_category_name(). '&nbsp;(' osc_category_total_items() . ')' ?></a></li>
Regards

Pathfinder

  • Newbie
  • *
  • Posts: 18
Re: Number of ads in sub categories
« Reply #13 on: February 01, 2014, 10:45:03 pm »
Thanks teseo

I have made some changes and my lines 52-61 now look like this - and it works :) I now have correct numbering for both parent and sub categories.

Code: [Select]
<ul class="nav">
                                <?php while ( osc_has_categories() ) { ?>
                                <li class="<?php echo osc_category_slug() ; ?><?php if ( osc_count_categories() > ) { ?> menu<?php ?>">
<a href="<?php echo osc_search_category_url() ; ?>" <?php if ( osc_count_categories() > ) { ?>class="menu"<?php ?>> <?php echo_osc_categories;?> <?php echo  '&nbsp;(' osc_category_total_items() . ')' ?> <?php View::newInstance()->_erase('subcategories'); echo osc_category_name() ; ?></a>                                 
<?php if ( osc_count_subcategories() > ) { ?>
                                    <ul class="menu-dropdown">
                                        <?php while ( osc_has_subcategories() ) { ?>
                                        <li class="<?php echo osc_category_slug() ; ?>"><a href="<?php echo osc_search_category_url() ; ?>"><?php echo osc_category_name(). '&nbsp;(' osc_category_total_items() . ')' ?></a></li>
                                        <?php ?>
                                    </ul>

Many thanks to everybody for your help!  :)  :)

I will wait until I have entered more data to confirm that it works as it should before claiming it as solved.

Pathfinder

  • Newbie
  • *
  • Posts: 18
Re: Number of ads in sub categories
« Reply #14 on: February 03, 2014, 10:34:02 pm »
OK, I've tried this several times and even copied it to another osclass installation and everything seems to work perfectly so I'm marking this as solved.

Thanks everybody for your help.