WordPress 中的条件语句
为什么这段代码工作正常:
<?php if (**is_page**('4')) { ?>
<style type="text/css">
body {background-image:url("<?php bloginfo('template_url'); ?>/images/bac4.jpg");}
</style>
<?php } else ?>
而这则不行:
<?php if (**is_category**()) { ?>
<style type="text/css">
body {background-image:url("<?php bloginfo('template_url'); ?>/images/coaching.jpg");}
</style>
<?php } else ?>
Why this code works fine:
<?php if (**is_page**('4')) { ?>
<style type="text/css">
body {background-image:url("<?php bloginfo('template_url'); ?>/images/bac4.jpg");}
</style>
<?php } else ?>
and this not:
<?php if (**is_category**()) { ?>
<style type="text/css">
body {background-image:url("<?php bloginfo('template_url'); ?>/images/coaching.jpg");}
</style>
<?php } else ?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在我的模板的 header.php 中为我工作。在模板的 archive.php 中添加一些内容,最好是在
is_category()
内,以验证您是否位于类别页面上。另外,我发现替代 if 语法更容易阅读和调试,但是 YMMV。Works for me in my template's header.php. Add some stuff to your template's archive.php, preferably inside the
is_category()
, to verify you're on a category page. Also, I find the alternative if syntax easier to read and debug, but YMMV.