boardom Forum Index boardom
b2 message board
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Too many categories...

 
Post new topic   Reply to topic    boardom Forum Index -> Hacks
View previous topic :: View next topic  
Author Message
xinit



Joined: 25 Jan 2003
Posts: 6

PostPosted: Tue Feb 04, 2003 5:46 pm    Post subject: Too many categories... Reply with quote

I was kind of sick of having so many categories show up on the sidebar, and I wasn't really able to filter them, as that defeats the purpose of listing them at all.

So, I altered the list_cats function in b2-include/b2template.functions.php

Allowing for another option to be fed into the function with the new $selectbox var. 1 meaning "display the results as options for a select box" ... I'm defaulting to this behaviour. All this bit of code does is display the <OPTION...> tags. You can wrap them in whatever SELECT code you choose to.
Code:

function list_cats($optionall = 1, $all = 'All', $sort_column = 'ID', $selectbox=1, $sort_order = 'asc', $file = 'blah') {
        global $tablecategories,$querycount;
        global $pagenow;
        global $querystring_start, $querystring_equal, $querystring_separator;
        $file = ($file == 'blah') ? $pagenow : $file;
        $sort_column = 'cat_'.$sort_column;
        $query="SELECT * FROM $tablecategories WHERE cat_ID > 0 ORDER BY $sort_column $sort_order";
        $result=mysql_query($query);
        $querycount++;
        if (intval($optionall) == 1) {
                $all = apply_filters('list_cats', $all);
                echo "\t<a href=\"".$file.$querystring_start.'cat'.$querystring_equal.'all">'.$all."</a><br />\n";
        }
        if ($selectbox == 1) {
                echo '\t<option value="">- - -';
                echo stripslashes($cat_name)."</option><br />\n";
        }
        while($row = mysql_fetch_object($result)) {
                $cat_name = $row->cat_name;
                $cat_name = apply_filters('list_cats', $cat_name);
                if ($selectbox == 1) {
                        echo "\t<option value=\"".$file.$querystring_start.'cat'.$querystring_equal.$row->cat_ID.'">';
                        echo stripslashes($cat_name)."</option><br />\n";
                } else {
                        echo "\t<a href=\"".$file.$querystring_start.'cat'.$querystring_equal.$row->cat_ID.'">';
                        echo stripslashes($cat_name)."</a><br />\n";
                }
        }
}




I opt for the no-button javascript onChange style of dropdown...

Code:

<FORM name="cat">
<SELECT name="bob" onChange="window.location=document.cat.bob.options[document.cat.bob.selectedIndex].value">
<?php list_cats(0, 'All', 'name'); ?>
</SELECT>
</FORM>


Of course, if I want to display the 'normal' category list, I just call it as...

Code:

<?php list_cats(0, 'All', 'name', 0); ?>
Back to top
View user's profile Send private message
ranmajen



Joined: 22 Nov 2004
Posts: 13

PostPosted: Sat Feb 12, 2005 11:11 am    Post subject: Reply with quote

I am using this one, can I add the post count in each category?
How to do so?
_________________
The Dark Heaven
The Vampire Coven
Laputa
Ryoga Hibiki
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    boardom Forum Index -> Hacks All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB 2 © 2001, 2002 phpBB Group