在Wordpress中,如何将body类添加到除主页之外的所有内部页面


In Wordpress how to add a body class to all interior pages except the homepage

我想在除主页之外的所有页面的body标记中添加一个类。现在我有。

<?php body_class('interior'); ?>

但它为包括主页在内的所有页面添加了"内部"。

将类添加到除"主页"之外的所有内部页面的body标记的最佳标准方法是什么?

http://codex.wordpress.org/Function_Reference/is_home

<?php if (!is_home()) body_class('interior'); ?>

除非你的意思是http://codex.wordpress.org/Function_Reference/is_front_page

<?php if (!is_front_page()) body_class('interior'); ?>

我认为最好的解决方案是写:

<body <?php if (!is_front_page()) body_class('interior'); ?> <?php body_class(); ?>>

通过这种方式,除了首页之外,您在所有页面中只添加class="interior",并且您可以在首页中保存类,否则,在主页中仅使用标记<body>中的第一个php代码时,您将没有类。