Osclass forums
Support forums => Themes => Twitter => Topic started by: Pathfinder 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
-
do you mean something like the original theme?
say Parkdean (23)
sub cat Cherry Tree (4) etc
-
Yes, that's exactly what I need.
-
Are you have try to add <?php echo osc_category_total_items() ; ?> functions ?
-
OK, thanks, but I'm very new to this, so where should I add that line?
-
Open your theme folder > functions.php and find this line
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 :
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
-
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?
-
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
-
Hi,
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() . ' (' . 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
-
Guys, Thanks for you help it is appreciated, however, so far I have not managed to get anything to work :(
Hi,
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() . ' (' . 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.
-
You have to replace this:
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):
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() . ' (' . osc_category_total_items() . ')' . '</option>' ;
}
Regards
-
Ok Guys, this is what I've done;
functions.php
I have changed lines 3 - 18
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
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() . ' (' . osc_category_total_items() . ')' . '</option>' ;
}
}
}
echo '</select>' ;
}
.............................
Header.php
Line 55
<a href="<?php echo osc_search_category_url() ; ?>" <?php if ( osc_count_subcategories() > 0 ) { ?>class="menu"<?php } ?>><?php View::newInstance()->_erase('subcategories'); echo osc_category_name() ; ?></a>
I have added
<?php echo_osc_catergories;?> <?php echo osc_category_total_items() ; ?>
To make
<a href="<?php echo osc_search_category_url() ; ?>" <?php if ( osc_count_subcategories() > 0 ) { ?>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?
-
<?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:
<li class="<?php echo osc_category_slug() ; ?>"><a href="<?php echo osc_search_category_url() ; ?>"><?php echo osc_category_name() ; ?></a></li>
with:
<li class="<?php echo osc_category_slug() ; ?>"><a href="<?php echo osc_search_category_url() ; ?>"><?php echo osc_category_name(). ' (' . osc_category_total_items() . ')' ; ?></a></li>
Regards
-
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.
<ul class="nav">
<?php while ( osc_has_categories() ) { ?>
<li class="<?php echo osc_category_slug() ; ?><?php if ( osc_count_categories() > 0 ) { ?> menu<?php } ?>">
<a href="<?php echo osc_search_category_url() ; ?>" <?php if ( osc_count_categories() > 0 ) { ?>class="menu"<?php } ?>> <?php echo_osc_categories;?> <?php echo ' (' . osc_category_total_items() . ')' ; ?> <?php View::newInstance()->_erase('subcategories'); echo osc_category_name() ; ?></a>
<?php if ( osc_count_subcategories() > 0 ) { ?>
<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(). ' (' . 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.
-
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.