Simple Machines Community Forum

Customizing SMF => Tips and Tricks => Topic started by: 1MileCrash on August 02, 2005, 04:16:06 PM

Title: Hiding a theme
Post by: 1MileCrash on August 02, 2005, 04:16:06 PM
This is Blocs work, im just posting it for anyone who may find it useful

This will hide any theme of your choice from the theme selection. This will come in handy if you are developing a theme, and want to keep it hidden for the time being, without denying your users the abilty to choose their style. They can still access the style by url though. It also came in handy for the way i am integrating my forum into my site.

in Themes.template.php, find-
// This template allows for the selection of different themes ;).
function template_pick()
{
        global $context, $settings, $options, $scripturl, $txt;

        // Just go through each theme and show its information - thumbnail, etc.
        foreach ($context['available_themes'] as $theme)
                echo '
        <table align="center" width="85%" cellpadding="3" cellspacing="0" border="0" class="tborder">
                <tr class="', $theme['selected'] ? 'windowbg' : 'windowbg2', '">
                        <td rowspan="2" width="126" height="120"><img src="', $theme['thumbnail_href'], '" alt="" /></td>
                        <td valign="top" style="padding-top: 5px;">
                                <div style="font-size: larger; padding-bottom: 6px;"><b><a href="', $scripturl, '?action=theme;sa=pick;u=', $context['current_member'], ';th=', $theme['id'], ';sesc=', $context['session_id'], '">', $theme['name'], '</a></b></div>
                                ', $theme['description'], '
                        </td>
                </tr>
                <tr class="', $theme['selected'] ? 'windowbg' : 'windowbg2', '">
                        <td valign="bottom" align="right" style="padding: 6px; padding-top: 0;">
                                <div style="float: left;" class="smalltext"><i>', $theme['num_users'], ' ', ($theme['num_users'] == 1 ? $txt['theme_user'] : $txt['theme_users']), '</i></div>
                                <a href="', $scripturl, '?action=theme;sa=pick;u=', $context['current_member'], ';th=', $theme['id'], ';sesc=', $context['session_id'], '">', $txt['theme_set'], '</a> |
                                <a href="', $scripturl, '?action=theme;sa=pick;u=', $context['current_member'], ';theme=', $theme['id'], ';sesc=', $context['session_id'], '">', $txt['theme_preview'], '</a>
                        </td>
                </tr>
        </table>
        <br />';
}


replace that with

// This template allows for the selection of different themes ;).
function template_pick()
{
        global $context, $settings, $options, $scripturl, $txt;

        $hidden_themeID= "X";

        // Just go through each theme and show its information - thumbnail, etc.
        foreach ($context['available_themes'] as $theme){
          if($theme['id'] != $hidden_themeID)
                echo '
        <table align="center" width="85%" cellpadding="3" cellspacing="0" border="0" class="tborder">
                <tr class="', $theme['selected'] ? 'windowbg' : 'windowbg2', '">
                        <td rowspan="2" width="126" height="120"><img src="', $theme['thumbnail_href'], '" alt="" /></td>
                        <td valign="top" style="padding-top: 5px;">
                                <div style="font-size: larger; padding-bottom: 6px;"><b><a href="', $scripturl, '?action=theme;sa=pick;u=', $context['current_member'], ';th=', $theme['id'], ';sesc=', $context['session_id'], '">', $theme['name'], '</a></b></div>
                                ', $theme['description'], '
                        </td>
                </tr>
                <tr class="', $theme['selected'] ? 'windowbg' : 'windowbg2', '">
                        <td valign="bottom" align="right" style="padding: 6px; padding-top: 0;">
                                <div style="float: left;" class="smalltext"><i>', $theme['num_users'], ' ', ($theme['num_users'] == 1 ? $txt['theme_user'] : $txt['theme_users']), '</i></div>
                                <a href="', $scripturl, '?action=theme;sa=pick;u=', $context['current_member'], ';th=', $theme['id'], ';sesc=', $context['session_id'], '">', $txt['theme_set'], '</a> |
                                <a href="', $scripturl, '?action=theme;sa=pick;u=', $context['current_member'], ';theme=', $theme['id'], ';sesc=', $context['session_id'], '">', $txt['theme_preview'], '</a>
                        </td>
                </tr>
        </table>
        <br />';
        }
}


replace "X" with the id to the theme you want to be hidden. It will no longer apear under theme selection.

Thanks Bloc, this helped me a ton.  :)


Title: Re: Hiding a theme
Post by: bloc on August 03, 2005, 12:23:21 PM
I have tested this and its nothing wrong with it. Themes change as they should.
Title: Re: Hiding a theme
Post by: 1MileCrash on August 03, 2005, 12:32:27 PM
 when i go to change themes, and click "Use this theme", it refreshes the page. Ill try again and post what happens.  :)


EDIT: nope, no good. I cant get it to work....did i put it in the wrong place or something?

Quote// --></script>';
}

// This template allows for the selection of different themes ;).
function template_pick()
{
        global $context, $settings, $options, $scripturl, $txt;

        $hidden_themeID= 2;

        // Just go through each theme and show its information - thumbnail, etc.
        foreach ($context['available_themes'] as $theme){
          if($theme['id'] != $hidden_themeID)
                echo '
        <table align="center" width="85%" cellpadding="3" cellspacing="0" border="0" class="tborder">
                <tr class="', $theme['selected'] ? 'windowbg' : 'windowbg2', '">
                        <td rowspan="2" width="126" height="120"><img src="', $theme['thumbnail_href'], '" alt="" /></td>
                        <td valign="top" style="padding-top: 5px;">
                                <div style="font-size: larger; padding-bottom: 6px;"><b><a href="', $scripturl, '?action=theme;sa=pick;u=', $context['current_member'], ';th=', $theme['id'], ';sesc=', $context['session_id'], '">', $theme['name'], '</a></b></div>
                                ', $theme['description'], '
                        </td>
                </tr>
                <tr class="', $theme['selected'] ? 'windowbg' : 'windowbg2', '">
                        <td valign="bottom" align="right" style="padding: 6px; padding-top: 0;">
                                <div style="float: left;" class="smalltext"><i>', $theme['num_users'], ' ', ($theme['num_users'] == 1 ? $txt['theme_user'] : $txt['theme_users']), '</i></div>
                                <a href="', $scripturl, '?action=theme;sa=pick;u=', $context['current_member'], ';th=', $theme['id'], ';sesc=', $context['session_id'], '">', $txt['theme_set'], '</a> |
                                <a href="', $scripturl, '?action=theme;sa=pick;u=', $context['current_member'], ';theme=', $theme['id'], ';sesc=', $context['session_id'], '">', $txt['theme_preview'], '</a>
                        </td>
                </tr>
        </table>
        <br />';
        }
}
// Okay, that theme was installed successfully!
function template_installed()
{
   global $context, $settings, $options, $scripturl

and, a test account:
Username: Test
Password: Test

How original :P

board url (http://paintplayers.com/smfthemes)
Title: Re: Hiding a theme
Post by: bloc on August 03, 2005, 01:26:50 PM
ah, I think its because that code is meant for SMF 1.1beta3, not smf1.0.5 as you have.

Sorry, I should checked with you about that. Here is the code for the 1.0.5:

// This template allows for the selection of different themes ;).
function template_pick()
{
        global $context, $settings, $options, $scripturl, $txt;

        $hidden_themeID= "2";
        // Just go through each theme and show its information - thumbnail, etc.
        foreach ($context['available_themes'] as $theme){
           if($theme['id'] != $hidden_themeID)
                echo '
        <table align="center" width="85%" cellpadding="3" cellspacing="0" border="0" class="tborder">
                <tr class="', $theme['selected'] ? 'windowbg' : 'windowbg2', '">
                        <td rowspan="2" width="126" height="120"><img src="', $theme['thumbnail_href'], '" alt="" /></td>
                        <td valign="top" style="padding-top: 5px;">
                                <div style="font-size: larger; padding-bottom: 6px;"><b><a href="', $scripturl, '?action=theme;sa=pick;u=', $context['current_member'], ';id=', $theme['id'], ';sesc=', $context['session_id'], '">', $theme['name'], '</a></b></div>
                                ', $theme['description'], '
                        </td>
                </tr>
                <tr class="', $theme['selected'] ? 'windowbg' : 'windowbg2', '">
                        <td valign="bottom" align="right" style="padding: 6px; padding-top: 0;">
                                <div style="float: left;" class="smalltext"><i>', $theme['num_users'], ' ', ($theme['num_users'] == 1 ? $txt['theme_user'] : $txt['theme_users']), '</i></div>
                                <a href="', $scripturl, '?action=theme;sa=pick;u=', $context['current_member'], ';id=', $theme['id'], ';sesc=', $context['session_id'], '">', $txt['theme_set'], '</a> |
                                <a href="', $scripturl, '?action=theme;sa=pick;u=', $context['current_member'], ';theme=', $theme['id'], ';sesc=', $context['session_id'], '">', $txt['theme_preview'], '</a>
                        </td>
                </tr>
        </table>
        <br />';
  }
}


Haven't got to test it though, but it maybe that whats causing this error. The main difference between it , is that in 1.1 "th=" is used, while in 1.0.5 "id=" is used instead.
Title: Re: Hiding a theme
Post by: 1MileCrash on August 03, 2005, 01:36:18 PM
that worked! Just a simple misunderstanding. Thanks for that.  :D
Title: Re: Hiding a theme
Post by: Gargoyle on August 03, 2005, 08:43:55 PM
What if you want to dissallow more than one theme ?

Can you add comma's like this... 2,4 ??
Title: Re: Hiding a theme
Post by: 1MileCrash on August 03, 2005, 08:48:58 PM
no. That wont work, because it will try to hide a theme with an id of 2, 4 (example), and it wont hide any. I tried it, and it unhid the one i had hidden.

Ill wait for someone to come up with a solution, because i dont know much about php.
Title: Re: Hiding a theme
Post by: Lucas3677 on August 03, 2005, 11:32:13 PM
$hidden_themeID = array('1', '2');

and then:

if(!in_array($theme['id'], $hidden_themeID))

Problem solved.
Title: Re: Hiding a theme
Post by: 1MileCrash on August 03, 2005, 11:33:29 PM
That guy Tippmaster is such a moron.
Title: Re: Hiding a theme
Post by: Cynthia Blue on August 10, 2005, 04:20:59 PM
Okay cool but... where is Themes.template.php in the directory tree?
Thanks.
Title: Re: Hiding a theme
Post by: 1MileCrash on August 10, 2005, 04:30:09 PM
it's in Themes/default

;D
Title: Re: Hiding a theme
Post by: unrelenting on August 22, 2007, 09:54:12 PM
This works well, BUT if you go to the screen where you choose your theme and hit one of the preview buttons it will show you that same screen using the chosen theme to preview it and THEN it won't be hiding the hidden themes. You can change to the hidden theme as well.  :-\
Title: Re: Hiding a theme
Post by: codenaught on August 22, 2007, 10:54:20 PM
Well keep in mind that this only hides the theme from being displayed on the theme listing page.

Quote
This will hide any theme of your choice from the theme selection. This will come in handy if you are developing a theme, and want to keep it hidden for the time being, without denying your users the abilty to choose their style. They can still access the style by url though. It also came in handy for the way i am integrating my forum into my site.

In no sense will this prevent users from changing their theme, they can even do it via url. Also I wasn't able to see the disabled theme myself when I selected to preview one of the themes.

In any case, I would say this tip may be a bit deprecated now that there is this mod - http://custom.simplemachines.org/mods/index.php?mod=391. Have you tried it out? This will not only hide the themes you want from being displayed but should also prevent the themes from being used at all. :)
Title: Re: Hiding a theme
Post by: unrelenting on August 23, 2007, 10:03:26 PM
Nice. No, I didn't know that was available. Thanks.
Title: Re: Hiding a theme
Post by: Mr Blah Man on November 24, 2007, 06:46:46 PM
I only know Java but even I know you can just make it:

$hidden_themeID= "1" || $hidden_themeID= "2";

The || means AND. You'd porbably be able to do && as well which means AND.

So its saying:

The hidden theme IDs are: ThemeID 1 AND/OR ThemeID 2.
Title: Re: Hiding a theme
Post by: bloc on November 25, 2007, 07:02:58 AM
In fact "||" means OR, while "&&" means AND. The statement will be true if either of the id's are correct. But it makes no sense to set AND there, a variable cannot be two different values at the same time!

Also..the syntax isn't correct in PHP, it will have to be:

if($hidden_themeID== "1" || $hidden_themeID== "2")