I've spent the day working in order to get category exclusion for the homepage loop working.
I have managed to get the backend UI working, so that a client can choose which categories to exclude in the theme admin panel.
I checked the db options table and sure enough the data is being saved properly.
example from the database sites options table -- all cats are either true or false like below
zoo_cat_box_4 true
--user checked box to exclude cat#4 in the admin
zoo_cat_box_5 true
--user checked box to exclude cat#5 in the admin
zoo_cat_box_6 false
--user did not check the box for cat#6 so it should show
That means I have the db setup properly.
(true next to cats that are excluded, false next to those not checked)
** 4,5,6 are the actual category id#'s, so that part is correct. I have an entry in the db for each category id#
Where I am stuck is the function to display this on the homepage.
Right now I have this function added to my themes functions file.
// Custom Homepage loop
function get_exclude_categories_loop() {
$include = array();
$counter = 0;
$cats = get_categories('hide_empty=0');
foreach ($cats as $cat) {
$counter++;
if ( get_option( "zoo_cat_box_".$cat->cat_ID ) == 'true') {
$excludecats[] = $cat->cat_ID;
}
}
if(!empty($excludecats)){
$excludecats = implode(',',$excludecats);
}
return $excludecats;
}
On my homepage I am using this code to call the loop:
<?php
query_posts(array('category__not_in' => array(get_exclude_categories_loop))); ?>
<?php if (have_posts()) : while (have_posts()) : the_post();
?>
Now if I change the homepage loop code "get_exclude_categories_loop" and replace that with numbers like 4,5,6 then categories 4,5,6 do not show up.
This means either my get_exclude_categories_loop function above is screwed up, or I'm not calling it correctly in the loop.
Well I know I am REALLY close to getting this right, but 1/2 a day later I'm stuck...
hoping a Ninja will recognize my mistake and let me know what I did wrong and why... (always trying to learn)
thanks
p.s.
How do I go about using var_dump on my get_exclude_categories_loop function to see what it's returning?
I've tried everything I can think of to see what the function is spitting out, but can't get the hang of var_dump. Otherwise I would know if it's my function or how I am calling it in my home.php file...