i want to apply templete.css only for index.php or home in joomla and apply mycss.css开发者_如何转开发 to other files . how can i do this . please help me
This is rather simple if you don't over think it. Joomla already has a page class suffix available in menu items that will allow you to control the CSS on a page based on the suffix of the page. This gives you ultimate control over each page without having to load differnt style sheets. You just need to add a little bit of code to your index.php file to make it all work.
Somewhere in the head add this php code -
$menu = &JSite::getMenu();
$active = $menu->getActive();
if (is_object( $active )) :
$params = new JParameter( $active->params );
$pageclass = $params->get( 'pageclass_sfx' );
endif;
Then replace your body tag with this -
<body id="<?php echo $pageclass ? $pageclass : 'default'; ?>">
If you specify a page class suffix for a menu item, that will be come the ID for the body, otherwise the ID will be "default". This makes it trivial to have page specific CSS.
You can do that by 2 ways ...
1) Create 2 Different Joomla Templates :
One that use template.css and the other use mycss.css then assign it to whatever pages you want.
2) Add this code to include your CSS file in the desired pages :
<?php if(JRequest::getCmd('Itemid') == 1 ) {?>
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/<?php echo $this->template ?>/css/mycss.css" type="text/css" />
<?php } ?>
And Change the Itemid to the Itemid you want to use.
If you want to use mycss.css on all pages except one page you can modify the code to be :
<?php if(JRequest::getCmd('Itemid') != 1 ) {?>
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/<?php echo $this->template ?>/css/mycss.css" type="text/css" />
<?php } ?>
That would do it.
In your "index.php" or "home in joomla" include only the "template.css" file
<link href="template.css" type="text/css" rel="stylesheet" />
In your "other Files" include ony the "mycss.css" file
<link href="mycss.css" type="text/css" rel="stylesheet" />
Hope I understood the question right
精彩评论