WordPress.org

Ready to get started?Download WordPress

Forums

Dropdown to select and change current theme (6 posts)

  1. wotto
    Member
    Posted 4 months ago #

    Hello, so we are working on a hosting site for restaurants where they will have option between three different themes. We are doing this through a multisite so they will each have their own subdomain and can apply whichever theme out of the three that they would like, and that all works fine.

    What we would like, however, is to have a demo site (also a subdomain, testsite.domain.com) where they can see the three different themes 'live', so essentially a dropdown in the header or sidebar to select one of the three themes and when they select a theme the page reloads but now with the selected theme applied to the demo site.

    I know that the current theme is in the rows template and stylesheet in the wp_n_options where n is the sub site ID. Is there any other way to change the theme rather than a direct SQL UPDATE? is it even safe to do a direct SQL UPDATE to the live database? I know theme sites such as elegantthemes.com have a live demo that is very similar to what i am describing but of course i cant know anything about their specific implementation. Im really struggling on finding any references online about this type of thing and would really appreciate any hints or sources that will help me out.

  2. wotto
    Member
    Posted 4 months ago #

    i found this page in the codex, but the plugins that it references are all super out-of-date...

    http://codex.wordpress.org/Theme_Switching

  3. bcworkz
    Member
    Posted 4 months ago #

    Why not let them use their site's theme Live Preview? Under the Appearance-Theme menu. They will only see themes installed for the network by Super Admin.

  4. wotto
    Member
    Posted 4 months ago #

    @bcworkz the problem is that this is for people who havent purchased a site yet so they wont have any login credentials, it is for anyone to use as a public site to see if they like our templates and then if they do they will purchase a site and can then change the theme from the admin menu

  5. bcworkz
    Member
    Posted 4 months ago #

    Ah, I see! I obviously had a different scenario in mind.

    I knew there are (outdated) plugins that switch themes, but I had no idea how they worked. We can still learn from plugins even if they are outdated. From Theme Test Drive, it appears one just needs to filter 'template' and 'stylesheet' and return the folder name of the theme you want to display. Here is my test code to display the twentyfourteen theme on my custom themed site:

    add_filter('template', 'return_twentyfourteen');
    add_filter('stylesheet', 'return_twentyfourteen');
    function return_twentyfourteen(){
    	return 'twentyfourteen';
    }

    I haven't done extensive testing, but this appears to be all that's necessary to display a particular theme. You of course would need much more code to return the user's selection instead of just 'twentyfourteen', but this serves at least as proof of concept. Learn something new every day! :)

  6. wotto
    Member
    Posted 4 months ago #

    awesome thank you! i will try that out and if i get a working solution i'll post it here for other people in the future who maybe looking for a similar sort of think, thanks again!

Reply

You must log in to post.

About this Topic