简体   繁体   中英

How to make my a cms that can change themes like tumblr

Hey guys. I was wondering how would I make theme options for a cms of mine like tumblr? I understand how to use the code like tumblr, {description}, {text} and variables like that but how would I make a theme switcher like this in php?

Simply put a php variable in your head section. Be sure to create the $userCSSchoice at the beginning of your page or you will break it all! Doom!

<LINK REL=StyleSheet HREF="<?php echo $userCSSchoice; ?>.css" TYPE="text/css" MEDIA=screen>

Nah, seriously, I do this and it works just fine for me. Then you have to create all those css stylesheets, but that's not too hard.

An alternative is to create your CSS page in PHP so you can pass a variable to a single sheet to determine the style.

<link rel=StyleSheet href="styles.php?theme=<?php echo $userCSSchoice; ?>" type="text/css" media=screen>

Then your PHP/CSS page can determine colors/images..

<?php
    header("Content-Type: text/css");

    if (isset($_REQUEST['theme']))
        $theme = $_REQUEST['theme'];
    else
        $theme="default";

    $bgImage="images/bg_".$theme.".png";    

    if ($theme=="default")
        $mainColor="0f8200";
    else if ($theme=="green")
        $mainColor="009900";

?>

body {
    background:url('<?php echo $bgImage; ?>')  repeat-x #<?php echo $bg; ?>;
    color: #<?php echo $mainColor; ?>;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM