Forum Moderators: open

Message Too Old, No Replies

PHP joomla 1.5 CSS change

         

Tuna_Vader

4:07 pm on Nov 6, 2008 (gmt 0)

10+ Year Member



Greetings,

i'm a newbie at web design, i'm using a cms for the first time and i'm having some problems.

I have a few pages, 4 to be exact and i have 4 different css files, one for each page. My problem is: how can i "attach" a css file to a page that's not the "frontpage/main/index.php".

I saw a post and i liked the solution but the problem is that on joomla, i just have 1 page and not several pages, so i can't atributte several id's depending on the page.

Can someone help me please?

On my folder /templates/exampleFolder/ i have an index.php. In the "head" i have something like this:

<link rel="stylesheet" href="templates/system/css/system.css" type="text/css" />
<link rel="stylesheet" href="templates/<?php echo $this->template ?>/css/template.css" type="text/css" />

well, i have a few css files, i would like to know how can i call other css files for other pages. If i change the info to "/css/template_example.css", he changes all the pages.

ergophobe

5:02 pm on Nov 7, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Welcome Tuna_Vader!

Can we back up just a little? It seems to me that having a different CSS file for every page defeats much of the purpose of having stylesheets in the first place. Ideally, a stylesheet helps set site-wide look and feel and having more than a couple of stylesheets will make site maintenance difficult.

Normally, when you have multiple stylesheets, it's because they serve different roles. For example, you might have

- typography.css for all your fonts
- layout.css for the basic page layout
- print.css for styles specific to printing on paper.

or
- sitename.css for styles shared across the site
- forum.css for the additional styles used on your forum pages.

In the latter case, you would always have sitename.css included on your pages, but would only have forum.css included if it were a forum page. You wouldn't typically have different stylesheets for each page. You would have your base stylesheet and possibly, if there were tons of rules that you didn't want in the base stylesheet, ancillary sheets that would get added in as needed.

If you find that you really, truly need different stylesheets for different pages, you can create a template for each page type and then use the Joomla template manager to assign a template to those page types. I'm not really a Joomla person, so I can't be much help there though.

coleus

3:51 pm on Nov 25, 2008 (gmt 0)

10+ Year Member



I agree completely with ergophobe about the optimization of CSS styles. However, I am beginning to learn Joomla CMS and I share the basis of Tuna_Vader's question: How to apply a different CSS or an additional CSS file to a particular page, given good reason to do so?

ergophobe

4:46 pm on Nov 25, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Okay, I begged off b/c I don't know the official Joomla way to do it. This is a bit of a hack, and not what I would do in Wordpress in Drupal, but it should work in any PHP script.

Let's say the page you want to add the stylesheet to is called

http://example.com/mystuff/mycoolpage

In your main page template, up where you declare the <head>, you could test to see if you're on that page, and then add in a stylesheet in the appropriate spot.

<?php
if (substr_count($_SERVER['REQUEST_URI'], "mystuff/mycoolpage"))
{
echo '<link href="/path/to/mycoolpage/stylesheet" rel="stylesheet" type="text/css" media="scree" />
}
?>

Essentially, that says "If the current page includes in its address the special page that gets the special stylesheet, then include that stylesheet. Otherwise, do nothing."

If you're using get parameters (index.php?q=page123) then you can test for those with the $_SERVER['QUERY_STRING'] variable in the same way, or much more simply by just asking

if ($_POST['q'] == "page123")

That should work, but I can 100% guarantee that a developer who knows Joomla would not do it this way. I believe a Joomla doc has a styles object of some sort and you can just add a stylesheet rather than the raw HTML.

HTH
Tom