【问题标题】:Add Custom CCS to Specific Template Pages in Wordpress将自定义 CSS 添加到 Wordpress 中的特定模板页面
【发布时间】: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 是一些有用的文档。

【问题讨论】:

    标签: php css wordpress themes


    【解决方案1】:

    确保您的主题支持 body_class。它应该在 body 标记中包含以下内容:

    <body <?php body_class(); ?>>
    

    如果是,请检查您的 if 条件是否返回 true,例如:

    if (is_page_template('pageshow.php')){
        echo 'ITS WORKING';
    }
    

    【讨论】:

      猜你喜欢
      • 2015-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多