How to change the PHP-Nuke theme depending on the module

14.11. How to change the PHP-Nuke theme depending on the module

For some web designs, it is desirable to always use the same theme for a few modules, while letting the user choose his own theme for the rest. Let's say you want to use the NukeNews theme for the News and Sections modules, but let the user's personal theme be applied to the other modules of your site.

The theme is set in the get_theme function of mainfile.php. Thus, all you have to do is declare the $name variable to be global in that function, then check its value before the selected theme is returned (i.e. immediately before the return statement) and, if it is, say "News", or "Sections", to choose the NukeNews theme (see Truly Global Variables):

function get_theme() {
    global $user, $cookie, $Default_Theme, $name; (1)
    if(is_user($user)) {
        $user2 = base64_decode($user);
        $t_cookie = explode(":", $user2);
        if($t_cookie[9]=="") $t_cookie[9]=$Default_Theme;
        if(isset($theme)) $t_cookie[9]=$theme;
        if(!$tfile=@opendir("themes/$t_cookie[9]")) {
            $ThemeSel = $Default_Theme;
        } else { 
            $ThemeSel = $t_cookie[9];
    } else {
        $ThemeSel = $Default_Theme;
    if ($name == "News" || $name == "Sections") { (2)
        $ThemeSel = "NukeNews"; (3)
    } else {
        /* Don't change the theme */    
Declare $name to be global.
Check if the module name, $name, is News or Sections.
Set the selected theme to NukeNews.

Of course, there is nothing magic about $name. You could take just any other variable and make the theme selection be dependent on it. You would only have to declare it global in the get_theme() function and in the modules that you would like to se t it.


Site Info v2.2.2

Last SeenLast Seen
  • neralex
  • FireATST
Server TrafficServer Traffic
  • Total: 379,202,366
  • Today: 6,076
Server InfoServer Info
  • Mar 25, 2019
  • 03:04 am CET