在我的 wordpress 模板中,我根据 wordpress 选项设置值更改 div 类。我有多个模板/pages ,所以我不想在每个模板页面上重复 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>
帮我创建一个返回 css 变量 $div
的 php 函数。
最佳答案
Havnt test it but something like this?
function getTemp( $WPtemplate , $pagewidth, $pagecolor ){
$divclass = array();
if( $WPtemplate == 1 ){
$divclass = array($pagewidth,$pagecolor );
$div = $divclass['0'].'-'.$divclass['1'].'-box';
return $div;
}
}
关于php - 创建 Php 函数以返回 css 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22551371/