douling6469 2013-05-13 04:03
浏览 33
已采纳

如何在Wordpress中创建每页和每个类别的样式表?

I'm trying to create many different skins that apply depending on the page and the category of my Wordpress site. I am not sure of two things:

  1. How to use an or statement in PHP to call on the skin1.css stylesheet if is_page('x') OR if is_category('1'). (On that note, how do you specify multiple pages and/or categories in the same line?
  2. Why is the following code displaying as text in the header of my web site?
  3. There must be a better way to write these if else statements. Any tips?

I know this is a mess.

    < ?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 } ?>
  • 写回答

2条回答 默认 最新

  • duan_88598 2013-05-13 19:26
    关注

    So, I got this to work.

    Originally I had used is_page('x') and then switched to is_category('x').

    That worked for the categories, explicitly. When a post belonging to one of those categories was visited, the stylesheet defaulted back to the original setting.

    It took some time and reading, but I found something that worked quite well (and looks prettier with the use of arrays).

     <?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 } ?>
    

    I added the !is_home() because something was throwing off my home page from the default setting and pulling in a specific stylesheet. I'm wondering if because the home page was the "front" page for the content that the in_category('x') was registering some of the excerpts as part of those equations.

    It's just a guess. I don't actually know, but that seemed to resolve the issue so far.

    Thanks again for all the help.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站