Simple Theme Changer

Started by Fustrate, August 19, 2008, 11:29:32 PM

Previous topic - Next topic

Fustrate

Link to Mod



Simple Theme Changer v1.0



Introduction
Simple Theme Changer allows users to switch themes from any page, without having to go to their profile - all you have to do is pick one from a dropdown list!

Features
o A dropdown box is placed in the bottom right side of most themes' footers. If it doesn't show up in your theme, add the following where you want it to appear (in index.template.php):
echo '
<select id="simple_theme_changer" onchange="switch_theme();">
<optgroup label="', $txt['simple_theme_changer_name'], '">';

foreach ($context['themes'] as $id => $theme)
echo '
<option value="', $id, '"', (($settings['theme_id'] == $id) ? ' selected="selected"' : ''), '>', $theme, '</option>';

echo '
</optgroup>
</select>

<script language="JavaScript" type="text/javascript">
<!--
function switch_theme(){
theme_changer = document.getElementById("simple_theme_changer");
var id = theme_changer.options[theme_changer.selectedIndex].value;
var page = new String(window.location);

window.location = "index.php?action=theme;sa=pick;type=quick;u=', $context['user']['id'] ,';th=" + id + ";sesc=', $context['session_id'], ';page=" + escape(page);
return false;
}
-->
</script>';

o To use this mod, just pick a theme from the dropdown menu ;)
o There are NO admin features for this modification.


Support
Please use the modification thread for support with this modification. Personal messages for support are discouraged.

Languages
o English
o English UTF-8
If you have any translations for any other languages, I would be grateful if you would send them to me via PM or in the Mods topic.

Changelog
> Comment
+ Addition
- Error/bug fix

Version 1.0 Aug. 16th, 2008
> Initial Release

(No Version Change) 12th February, 2009
> Upgraded for RC1, 1.1.x support added.
Steven Hoffman
Former Team Member, 2009-2012

Nathaniel

Wow, very nice little mod! :D

I have seen this sort of thing around quite a few different theme demo sites. ;)
SMF Friend (Former Support Specialist) | SimplePortal Developer
My SMF Mods | SimplePortal

"Quis custodiet ipsos custodes?" - Who will Guard the Guards?

Please don't send me ANY support related PMs. I will just delete them.

Fustrate

ya, and there was a mod that was last updated... some time last year? But as far as I could tell there wasn't one for 2.0 :P
Steven Hoffman
Former Team Member, 2009-2012

.HuNTeR.

if you write a version for 1.1.5 it will be great

Nathaniel

[sarcasm]

Hmm, just thinking aloud, anyway of making this use Ajax to change the theme? ;D

[/sarcasm]
SMF Friend (Former Support Specialist) | SimplePortal Developer
My SMF Mods | SimplePortal

"Quis custodiet ipsos custodes?" - Who will Guard the Guards?

Please don't send me ANY support related PMs. I will just delete them.

Dark-Wizard

Where in the Index.template.php am i supposed to put the code?

Fustrate

It really depends on your theme... sometimes you can go to
</div>';
}

function template_html_below()


and replace it with
<select id="simple_theme_changer" onchange="switch_theme();">
   <optgroup label="', $txt['simple_theme_changer_name'], '">';

foreach ($context['themes'] as $theme)
   echo '
      <option value="', $theme['id'], '"', (($settings['theme_id'] == $theme['id']) ? ' selected="selected"' : ''), '>', $theme['name'], '</option>';

echo '
   </optgroup>
</select>

<script language="JavaScript" type="text/javascript">
   <!--
   function switch_theme(){
      theme_changer = document.getElementById('simple_theme_changer');
      var id = theme_changer.options[theme_changer.selectedIndex].value;
      var page = new String(window.location);

      window.location', $context['browser']['is_safari'] ? '.href' : '', ' = 'index.php?action=theme;sa=pick;type=quick;u=', $context['user']['id'] ,';th=' + id + ';sesc=', $context['session_id'], ';page=' + escape(page);
   }
   -->
</script>
</div>';
}

function template_html_below()
Steven Hoffman
Former Team Member, 2009-2012

Dark-Wizard

That gave me errors :( is there by chance i can send you the files?

Fustrate

Steven Hoffman
Former Team Member, 2009-2012

Dark-Wizard

1. Mystic Jade
2. BacknBlack
3. ClanWar
4. OverView

Please return them in the same order and thank you! :p i love your mods <.<

Fustrate

Argh, I really have to leave...

try placing this right before the ending bracket (}) of template_body_below, right after the </div>';

echo '
<select id="simple_theme_changer" onchange="switch_theme();">
   <optgroup label="', $txt['simple_theme_changer_name'], '">';

foreach ($context['themes'] as $theme)
   echo '
      <option value="', $theme['id'], '"', (($settings['theme_id'] == $theme['id']) ? ' selected="selected"' : ''), '>', $theme['name'], '</option>';

echo '
   </optgroup>
</select>

<script language="JavaScript" type="text/javascript">
   <!--
   function switch_theme(){
      theme_changer = document.getElementById(\'simple_theme_changer\');
      var id = theme_changer.options[theme_changer.selectedIndex].value;
      var page = new String(window.location);

      window.location', $context['browser']['is_safari'] ? '.href' : '', ' = \'index.php?action=theme;sa=pick;type=quick;u=', $context['user']['id'] ,';th=\' + id + \';sesc=', $context['session_id'], ';page=\' + escape(page);
   }
   -->
</script>';


make sure it's AFTER the '; and before the }

and sorry about having to leave... I had no clue I was going to a Dodger game tonight
Steven Hoffman
Former Team Member, 2009-2012

Dark-Wizard

I still keep getting the same error :( may you attempt it when you return?

Dark-Wizard


Fustrate

attach your index.template.php to a post
Steven Hoffman
Former Team Member, 2009-2012

Dark-Wizard

I already did. its one of the posts above.

Fustrate

Oi, you're the one with 4...

Follow the example in this one, it's the first of the 4 themes:
Steven Hoffman
Former Team Member, 2009-2012

Dark-Wizard

Thank you :P and my site is hxxp:www.thefinalgathering.co.cc [nonactive] <.< check it out some time XD and ill be putting in the file as soon as i return back home.

Darkness_

what do I have to do, when I don't let a theme in that list?
something like, I want ID: 1, 2, 3, 5, 8
Maybe an array or something?

Fustrate

If you only want certain themes, find this in index.template.php:
foreach ($context['themes'] as $theme)

and add this right after it:
if(in_array($my_themes, $theme['id']))

and right before the foreach(), on the line before it add:
$my_themes = array(1,2, 3, 5, 8);
Steven Hoffman
Former Team Member, 2009-2012

Darkness_

BTW: could't this theme be compatible with the 1.1.X version of SMF.
I could help if you want.

Advertisement: