【发布时间】:2013-12-05 07:25:48
【问题描述】:
我希望使用 body_class_filter 将条目标题集中在我的 Wordpress 模板中的某些页面上。这将基于所使用的页面模板。
例如任何使用页面模板 pageshow.php 的页面都应该有自定义 CSS 来使标题居中。
我已经阅读了一些教程并了解需要做什么。但我的解决方案尝试不起作用。这是我尝试过的...
我把下面的内容放在我的functions.php文件的底部...
if (is_page_template('pageshow.php'))
{ // Returns true when 'pageshow.php' is being used.
function my_class_names($classes)
{ // add 'class-name' to the $classes array
$classes[] = 'pageshowclass';
return $classes; // return the $classes array
}
// Now add pageshowclass class to the filter
add_filter('body_class', 'my_class_names');
}
else
{ // Returns false when 'about.php' is not being used.
}
我的样式表中的以下内容...
/* Custom Page Styling by ID */
.pageshowclass h1.entry-title {
text-align: center;
}
但是类没有应用,css也没有。 Here 是一些有用的文档。
【问题讨论】: