创建返回css类的Php函数


Creating Php function to return css class

在我的wordpress模板中,我正在根据wordpress选项设置值更改div类。我有多个模板/页面,所以不是在每个模板页面上重复php代码,我想创建一个函数来返回变量css类(这里是$div)。

Wordpress选项设置有2个变量:$pagewidth &$pagecolor

PHP:

 <?php
    $pagewidth = 'big'; //big,small or tinny
    $pagecolor =  'white'; //white or black
    $divclass = array();
    $divclass = array($pagewidth,$pagecolor );
    $div = $divclass['0'].'-'.divclass['1'].'-box';
?>
css:

.big-white-box{width:100%;height:100%;background:url(images/big-white.png) repeat;}
.big-black-box{width:100%;height:100%;background:url(images/big-black.png) repeat;}
.small-white-box{width:100%;height:100%;background:url(images/small-white.png) repeat;}
.small-black-box{width:100%;height:100%;background:url(images/small-black.png) repeat;}
.tinny-white-box{width:100%;height:100%;background:url(images/tinny-white.png) repeat;}
.tinny-black-box{width:100%;height:100%;background:url(images/tinny-black.png) repeat;}
HTML:

<div class="<?php echo $div; ?>" >

<!--content-goes-here--->
</div>

帮助我创建一个php函数返回css变量$div

还没有测试过吗?

function getTemp( $WPtemplate , $pagewidth, $pagecolor ){
    $divclass = array();
    if( $WPtemplate == 1 ){
        $divclass = array($pagewidth,$pagecolor );
        $div = $divclass['0'].'-'.$divclass['1'].'-box';
        return $div;
    }
}