我在 WordPress 中使用了一个主题,但我想使用 php 手动更改“contents div”的 css,这就是我目前正在尝试做的事情:
<div id="main" class="site-main">
<div class="content" style="<?php if (is_page('Contact Us'){ echo 'width: 870px;'; } ?>">
<div class="lft">
<?php if(have_posts()) : ?>
<?php while ( have_posts() ) : the_post() ?>
<div class="horizontal-divider">
<h1><?php the_title(); ?></h1>
</div>
<?php the_content(); ?>
<?php endwhile; ?>
<?php endif; ?>
</div>
<div class="rgt">
<?php
get_sidebar();
?>
</div>
</div>
</div>
<?php get_footer(); ?>
正如你所看到的这一行:
<div class="content" style="<?php if (is_page('Contact Us'){ echo 'width: 870px;'; } ?>">
我正在尝试使用 php 将 div 的大小更改为 100%,但我不断收到此错误:
Parse error: syntax error, unexpected '{' in C:\xampp\htdocs\wp\aaco\wp-content\themes\aaco-theme\index.php on line 4
最佳答案
您忘记关闭 if
条件。
if (is_page('Contact Us'))
------------------^
关于php - WordPress if条件为div添加样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19247282/