In my wordpress template I am changing div class according to wordpress option setting values. I have multiple template /pages , so instead of repeating the php code on each template page, I want to create a function to return variable css class( $div
here).
Wordpress option setting gives 2 variables: $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>
Help me to create a php function which return css variable $div
.
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;
}
}
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.