【发布时间】:2016-01-22 07:30:30
【问题描述】:
我正在 Wordpress 中构建自定义主题,当 URL 以 ?checklist-view=1 结尾时,我需要向 body 标记添加 CSS 属性
我下面的代码有什么问题,因为没有添加全屏?
我知道我需要使用超全局 $_GET,但是我对 PHP 完全陌生。
有没有更简单的方法来使用 body_class 模板标签(就像我在下面尝试的那样)或者这需要更复杂的 PHP
编辑: 将 $class 更改为等于字符串,而不是将其设置为数组。
<!doctype html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo('charset'); ?>" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=0">
<title>Process Street <?php wp_title(); ?></title>
<link rel="profile" href="http://gmpg.org/xfn/11" />
<link rel="stylesheet" href="<?php echo get_stylesheet_uri(); ?>" type="text/css" media="screen" />
<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>" />
<!--[if lt IE 9]>
<script src="<?php echo get_stylesheet_uri(); ?>bower_components/html5shiv/dist/html5shiv.js"></script>
<![endif]-->
<?php wp_head(); ?>
</head>
<?php
//?checklist-view=1
$is_checklist = $_GET['checklist-view'];
$class= 'fullscreen';
if($is_checklist == '1') {
echo $class;
}
?>
<body <?php body_class($class); ?>>
【问题讨论】: