Skip to content Skip to sidebar Skip to footer

Php Page Navigation Using Arrays And Foreach, Trouble With Category Level = Active

So, in another post, CBroe was ever so helpful, along with @MeathCoder to illustrate the needed changes. I've since been able to do the whole thing and it looks amazing, but I'm ha

Solution 1:

Found a simple solution!

$cat_options = [
    ['category' => '1', 'active' => '', 'category_image' => 'fa fa-th-large', 
    'category_name' => 'Dashboard'],
    ['category' => '2', 'active' => '', 'category_image' => 'fas fa-battery-half', 
    'category_name' => 'Health'],
    ['category' => '3', 'active' => '', 'category_image' => 'fas fa-wrench', 
    'category_name' => 'Tools'],
    ['category' => '4', 'active' => '', 'category_image' => 'fas fa-user-secret', 
    'category_name' => 'Administration'],
    ];

Added a new field to the array and then in the logic for page=page, I set that field to active.

if( $_SERVER['PHP_SELF'] == $url ){
        // active
        $arr[$key]['css_class']    = 'active';
        $cat_options[$nav_opt['category']]['active']     = 'active';
        $arr[$key]['link_href']    = $url;
        $arr[$key]['link_text']    = $nav_opt['link_text'];
        $arr[$key]['category']     = $nav_opt['category'];
        $arr[$key]['link_display'] = $nav_opt['link_display'];        
    }

Post a Comment for "Php Page Navigation Using Arrays And Foreach, Trouble With Category Level = Active"