Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在Wordpress中创建每页和每类样式表?_Php_Wordpress - Fatal编程技术网

Php 如何在Wordpress中创建每页和每类样式表?

Php 如何在Wordpress中创建每页和每类样式表?,php,wordpress,Php,Wordpress,我正在尝试创建许多不同的皮肤,它们根据我的Wordpress站点的页面和类别而应用。我不确定有两件事: 如果是页面('x')或者是类别('1'),如何在PHP中使用or语句调用skin1.css样式表。(请注意,如何在同一行中指定多个页面和/或类别 为什么以下代码在我的网站标题中显示为文本 一定有更好的方法来写这些if-else语句。有什么提示吗 我知道这是一团糟 < ?php if (is_page( 'health' ) ) { ?> <link rel="

我正在尝试创建许多不同的皮肤,它们根据我的Wordpress站点的页面和类别而应用。我不确定有两件事:

  • 如果
    是页面('x')
    或者
    是类别('1')
    ,如何在PHP中使用or语句调用skin1.css样式表。(请注意,如何在同一行中指定多个页面和/或类别
  • 为什么以下代码在我的网站标题中显示为文本
  • 一定有更好的方法来写这些if-else语句。有什么提示吗
  • 我知道这是一团糟

        < ?php if (is_page( 'health' ) ) { ?>
        <link rel="stylesheet" type="text/css" href="<?php bloginfo('template_url'); ?>/css/skins/health-skin.css" />
        < ?php } elseif (is_page( 'beauty' ) ) { ?>
        <link rel="stylesheet" type="text/css" href="<?php bloginfo('template_url'); ?>/css/skins/beauty-skin.css" />
        < ?php } elseif (is_page( 'home' ) ) { ?>
        <link rel="stylesheet" type="text/css" href="<?php bloginfo('template_url'); ?>/css/skins/home-skin.css" />
        < ?php } elseif (is_page( 'food' ) ) { ?>
        <link rel="stylesheet" type="text/css" href="<?php bloginfo('template_url'); ?>/css/skins/food-skin.css" />
        < ?php } elseif (is_page( 'travel' ) ) { ?>
        <link rel="stylesheet" type="text/css" href="<?php bloginfo('template_url'); ?>/css/skins/travel-skin.css" />
        < ?php } else { ?>
        <link rel="stylesheet" type="text/css" href="<?php bloginfo('template_url'); ?>/css/skins/default-skin.css" />
        < ?php } ?>
    
    
    

    所以,我让它起作用了

    最初我使用了
    is\u页面('x')
    ,然后切换到
    is\u类别('x')

    当访问属于这些类别之一的帖子时,样式表默认返回到原始设置

    这需要一些时间和阅读,但我发现有些东西工作得很好(使用数组看起来更漂亮)

    
    
    好的,在我等待答案的同时,我继续在谷歌上搜索。我将代码更改为:我走对了吗?编辑:显然不是解决方案。我得到以下错误:解析错误:语法错误,意外的T_字符串,第48行应为“,”或“;我将在等待答案的同时继续计算。在你的粘贴箱中您应该更改echo字符串中的
    语句,打开和关闭字符串的操作是错误的:)那么
    “\”
    与JavaScriptor相同的错误您是说将“全部”转换为"或者仅仅是围绕echo后面的样式表行的样式表?就我记忆中的旧php时代而言……应该是这样的<代码>echo',另一种选择是使用一个样式表,其中包含针对特定页面和类别的规则。这些规则必须在CSS预处理器中编写吗?没有CSS预处理器:)有趣!:)CSS是一种运行时语言,它由浏览器结合相应的html标记/选择器来解释,但我熟悉像SASS这样的预处理器,尽管我没有使用过它们。我想我不清楚如何在样式表中编写针对可变页面/类别的规则。Tom,许多WP主题包括添加CLA的javascriptses到body或html元素,以表示它是什么类型的页面(即单个、类别、归档、主页、博客等)。这样,您就可以编写CSS来选择特定的内容类型,而无需使用PHP将其他样式表排队。我想,即使是默认主题也有此功能-我将对此进行研究。
    &&  //=and
    ||  //=or
    !== //=not same as
    !   //=not
    
     <?php if ( !is_home() && in_category( array( 'health-fitness', 'fitness', 'health-fitness-blogs', 'menopause', 'nutrition', 'vitaminminerals-chart', 'weight-management', 'health' ) )) { ?>
     <link rel="stylesheet" href="<?php bloginfo('stylesheet_directory'); ?>/css/skins/health-skin.css" type="text/css" media="screen" />
     <?php } ?>