Advertisement:

Author Topic: main.php - only certain categories  (Read 874 times)

spevoli

  • Jr. Member
  • **
  • Posts: 83
main.php - only certain categories
« on: April 07, 2016, 01:48:48 pm »
Hi

this code I have from @teseo "thanks"

Code: [Select]
<?php
function cust_show_only_selected_categories() {
    if(
osc_is_home_page()) {
        
$categoriesToShow = array(3159875); // Put here Id's of parent categories or subcategories (no sub-subcategories)
    
        
$categories Category::newInstance()->toTree();
        foreach (
$categories as $key => $cat) {
            if (!
in_array($cat['pk_i_id'], $categoriesToShow)) {
                foreach (
$cat['categories'] as $key2 => $subcat) {
                    if(!
in_array($subcat['pk_i_id'], $categoriesToShow)) {
                        unset(
$categories[$key]['categories'][$key2]);
                    }
                }
    
                if (!
$categories[$key]['categories']) unset($categories[$key]);
            }
        }
    
        
View::newInstance()->_exportVariableToView('categories'$categories);
    }
}

osc_add_hook('before_html''cust_show_only_selected_categories');
?>

does not display correctly ...
It will display all categories ... continue

someone has a tip?

thanks, spevoli


teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: main.php - only certain categories
« Reply #1 on: April 07, 2016, 04:37:12 pm »
Hi,

It's still working for me on Bender, what theme are you using? ???

Regards

spevoli

  • Jr. Member
  • **
  • Posts: 83
Re: main.php - only certain categories
« Reply #2 on: April 07, 2016, 04:50:29 pm »
Hello!

i have the "infinity" theme as a basis

spevoli

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: main.php - only certain categories
« Reply #3 on: April 07, 2016, 05:53:47 pm »
Works for me on Infinity as well... ??? Did you put this function at the very bottom of infinity/functions.php? ???

Or maybe you have there another function manipulating categories list just as this function does? ???

Regards

spevoli

  • Jr. Member
  • **
  • Posts: 83
Re: main.php - only certain categories
« Reply #4 on: April 07, 2016, 06:13:29 pm »

Hi Teseo!

in the "functions.php" I've changed a lot ...

for the area "category" not ...
the code I added at the bottom ...
There will be no error message  :-\

Spevoli