【问题标题】:How to load a style for one page in wordpress site [closed]如何在wordpress网站中为一页加载样式[关闭]
【发布时间】:2016-07-04 10:09:01
【问题描述】:

我只想为我的 wordpress 网站上的一个页面创建一个独特的样式。这是我在functions.php 或style.css 中做的事情,还是我需要创建一个新的页面模板?无论哪个选项正确,我如何定位相关页面?

【问题讨论】:

  • header.php添加条件:-<?php if($_SERVER['REQUEST_URI'] == 'give your page full url here'){?> link of style sheet <?php}else{?> link of all other style sheets <?php}?>

标签: php css wordpress styles themes


【解决方案1】:

一种方法是使用 body_class 并为该页面编写带有特定 body_class 选择器的 css 样式。

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

如果你还没有,把它放在你的开始身体标签上。

【讨论】:

    【解决方案2】:

    解决此问题的另一种方法是创建第二个标头,以引入此新样式表。然后不要像这样构建你的页面:

    <?php get_header();?>
    // Body Content
    <?php get_footer;?>
    

    你可以这样做:

    <?php get_template_part('new_header');?>
    // Body Content
    <?php get_footer; ?>
    

    只需将 new_header 替换为新的 php 文件名即可,只需保留扩展名即可。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-08-28
      • 2014-10-08
      • 2015-05-07
      • 1970-01-01
      • 1970-01-01
      • 2020-04-26
      • 1970-01-01
      相关资源
      最近更新 更多