xinit
Joined: 25 Jan 2003 Posts: 6
|
Posted: Tue Feb 04, 2003 5:46 pm Post subject: Too many categories... |
|
|
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); ?>
|
|
|