Author Topic: Not showing some categories  (Read 5036 times)

0 Members and 1 Guest are viewing this topic.

Offline Sun Zaza

  • Sr. Member
  • ****
  • Posts: 399
    • View Profile
Not showing some categories
« on: December 12, 2010, 10:13:43 PM »
Hi,

For some reasons I don't want to show some categories on the homepage (index.php/home.html). (It has nothing to do with user/category permissions)

I will explain:
I added an additional category field: cat_not_show

In functions.php I need help to tweak the function "get_categories" to make it not showing the category with cat_not_show = 1:

function get_categories($cat_id 0) {
  global 
$site_template$site_db$site_sess$config$lang;
  global 
$cat_cache$cat_parent_cache$new_image_cache$subcat_ids;

  
$cattable_width ceil((intval($config['cat_table_width'])) / $config['cat_cells']);
  if ((
substr($config['cat_table_width'],-1)) == "%") {
    
$cattable_width .= "%";
  }

  if (!isset(
$cat_parent_cache[$cat_id])) {
    return 
"";
  }

  
$visible_cat_cache = array();
  foreach (
$cat_parent_cache[$cat_id] as $key => $val) {
    if (
check_permission("auth_viewcat"$val)) {
      
$visible_cat_cache[$key] = $val;
    }
  }

  if (empty(
$visible_cat_cache)) {
    return 
"";
  }

  
$total sizeof($visible_cat_cache);
  
$table_columns = (intval($config['cat_cells'])) ? intval($config['cat_cells']) : 2;
  if (
$total <= $table_columns) {
    
$table_rows 1;
  }
  else {
    
$table_rows $total $table_columns;
    if (
$total >= $table_columns && !is_integer($table_rows)) {
      
$table_rows intval($table_rows) + 1;
    }
  }

  
$categories "\n<table width=\"".$config['cat_table_width']."\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n<td valign=\"top\" width=\"".$cattable_width."\" class=\"catbgcolor\">\n";
  
$categories .= "<table border=\"0\" cellpadding=\"".$config['cat_table_cellpadding']."\" cellspacing=\"".$config['cat_table_cellspacing']."\">\n";
  
$count 0;
  
$count2 0;
  foreach (
$visible_cat_cache as $key => $category_id) {
    
$categories .= "<tr>\n<td valign=\"top\">\n";

    
$is_new = (isset($new_image_cache[$category_id]) && $new_image_cache[$category_id] > 0) ? 0;
    
$num_images = (isset($cat_cache[$category_id]['num_images'])) ? $cat_cache[$category_id]['num_images'] : 0;

    
$subcat_ids = array();
    
get_subcat_ids($category_id$category_id$cat_parent_cache);

    if (isset(
$subcat_ids[$category_id])) {
      foreach (
$subcat_ids[$category_id] as $val) {
        if (isset(
$new_image_cache[$val]) && $new_image_cache[$val] > 0) {
          
$is_new 1;
        }
        if (isset(
$cat_cache[$val]['num_images'])) {
          
$num_images += $cat_cache[$val]['num_images'];
        }
      }
    }

    if (
defined("SHOW_RANDOM_IMAGE") && SHOW_RANDOM_IMAGE == || defined("SHOW_RANDOM_CAT_IMAGE") && SHOW_RANDOM_CAT_IMAGE == 0) {
      
$random_cat_image_file "";
    }
    else {
      
$random_cat_image_file get_random_image($category_id01);
    }

    
$site_template->register_vars(array(
      
"cat_id" => $category_id,
      
"cat_name" => format_text($cat_cache[$category_id]['cat_name'], 2),
      
"cat_description" => format_text($cat_cache[$category_id]['cat_description'], 1),
      
"cat_hits" => $cat_cache[$category_id]['cat_hits'],
      
"cat_is_new" => $is_new,
      
"lang_new" => $lang['new'],
      
"sub_cats" => get_subcategories($category_id),
      
"cat_url" => $site_sess->url(ROOT_PATH."categories.php?".URL_CAT_ID."=".$category_id),
      
"random_cat_image_file" => $random_cat_image_file,
      
"num_images" => $num_images
    
));
    
$categories .= $site_template->parse_template("category_bit");
    
$count++;
    
$count2++;
    
$categories .= "</td>\n</tr>\n";

    if (
$count == $table_rows && $count2 sizeof($visible_cat_cache)) {
      
$categories .= "</table></td>\n";
      
$categories .= "<td valign=\"top\" width=\"".$cattable_width."\" class=\"catbgcolor\">\n";
      
$categories .= "<table border=\"0\" cellpadding=\"".$config['cat_table_cellpadding']."\" cellspacing=\"".$config['cat_table_cellspacing']."\">\n";

      
$total $total $count2;
      
$table_columns $table_columns 1;
      
/*if ($total <= $table_columns && $table_columns > 1) {
        $table_rows = 1;
      }
      else {
        $table_rows = $total / $table_columns;
        if ($total >= $table_columns && !is_integer($table_rows)) {
          $table_rows = intval($table_rows) + 1;
        }
      }*/
      
$count 0;
    }
  }

  
$categories .= "</table>\n</td>\n</tr>\n</table>\n";
  return 
$categories;
}


Any help will be aprrecaited,

Thanks in advance,
Cruxy

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: Not showing some categories
« Reply #1 on: December 12, 2010, 11:11:30 PM »
Replace   foreach ($cat_parent_cache[$cat_id] as $key => $val) {
    if (
check_permission("auth_viewcat"$val)) {
      
$visible_cat_cache[$key] = $val;
    }
  }


with:
  $exclude = array(1,2,3);//categories you don't want show
  
foreach ($cat_parent_cache[$cat_id] as $key => $val) {
    if (
check_permission("auth_viewcat"$val)) {
      if (!
$cat_id && in_array($val$exclude)) continue;
      
$visible_cat_cache[$key] = $val;
    }
  }
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Sun Zaza

  • Sr. Member
  • ****
  • Posts: 399
    • View Profile
Re: Not showing some categories
« Reply #2 on: December 12, 2010, 11:36:10 PM »
Thanks V@no for your reaction.

It works fine with categories, but not with subcategories.

How can we implement that?

Thanks in advance,
Cruxy

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: Not showing some categories
« Reply #3 on: December 12, 2010, 11:58:17 PM »
Pretty much the same thing. Find:

  foreach ($cat_parent_cache[$parent_id] as $key => $val) {
    if (
check_permission("auth_viewcat"$val)) {
      
$visible_cat_cache[$key] = $val;
    }
  }


Replace it with:
  $exclude = array(1,2,3);//categories you don't want show
  
foreach ($cat_parent_cache[$parent_id] as $key => $val) {
    if (
check_permission("auth_viewcat"$val)) {
      if (!
$parent_id && in_array($val$exclude)) continue;
      
$visible_cat_cache[$key] = $val;
    }
  }
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Sun Zaza

  • Sr. Member
  • ****
  • Posts: 399
    • View Profile
Re: Not showing some categories
« Reply #4 on: December 13, 2010, 12:09:25 AM »
I got this error:

WarningInvalid argument supplied for foreach() in /hsphere/local/home/***/*****/includes/functions.php on line 1479 

Do you know why?

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: Not showing some categories
« Reply #5 on: December 13, 2010, 01:40:46 AM »
Maybe you replaced something else? The second code I showed is not replacing of the first one, it's an additional.
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)