Simple Machines Community Forum

Customizing SMF => Tips and Tricks => Thema gestartet von: 1MileCrash in August 02, 2005, 04:16:06 NACHMITTAGS

Titel: Hiding a theme
Beitrag von: 1MileCrash in August 02, 2005, 04:16:06 NACHMITTAGS
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.  :)


Titel: Re: Hiding a theme
Beitrag von: bloc in August 03, 2005, 12:23:21 NACHMITTAGS
I have tested this and its nothing wrong with it. Themes change as they should.
Titel: Re: Hiding a theme
Beitrag von: 1MileCrash in August 03, 2005, 12:32:27 NACHMITTAGS
 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?

Zitat// --></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)
Titel: Re: Hiding a theme
Beitrag von: bloc in August 03, 2005, 01:26:50 NACHMITTAGS
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.
Titel: Re: Hiding a theme
Beitrag von: 1MileCrash in August 03, 2005, 01:36:18 NACHMITTAGS
that worked! Just a simple misunderstanding. Thanks for that.  :D
Titel: Re: Hiding a theme
Beitrag von: Gargoyle in August 03, 2005, 08:43:55 NACHMITTAGS
What if you want to dissallow more than one theme ?

Can you add comma's like this... 2,4 ??
Titel: Re: Hiding a theme
Beitrag von: 1MileCrash in August 03, 2005, 08:48:58 NACHMITTAGS
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.
Titel: Re: Hiding a theme
Beitrag von: Lucas3677 in August 03, 2005, 11:32:13 NACHMITTAGS
$hidden_themeID = array('1', '2');

and then:

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

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

;D
Titel: Re: Hiding a theme
Beitrag von: unrelenting in August 22, 2007, 09:54:12 NACHMITTAGS
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.  :-\
Titel: Re: Hiding a theme
Beitrag von: codenaught in August 22, 2007, 10:54:20 NACHMITTAGS
Well keep in mind that this only hides the theme from being displayed on the theme listing page.

Zitat
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. :)
Titel: Re: Hiding a theme
Beitrag von: unrelenting in August 23, 2007, 10:03:26 NACHMITTAGS
Nice. No, I didn't know that was available. Thanks.
Titel: Re: Hiding a theme
Beitrag von: Mr Blah Man in November 24, 2007, 06:46:46 NACHMITTAGS
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.
Titel: Re: Hiding a theme
Beitrag von: bloc in November 25, 2007, 07:02:58 VORMITTAG
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")