SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Member
    Join Date
    Jul 2013
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how to link stylesheet in php file???

    how can i link my all stylesheets in php file????

  2. #2
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    6,008
    Mentioned
    219 Post(s)
    Tagged
    12 Thread(s)
    I'm sorry, I don't really understand the question.
    Could you elaborate?

    Normally you can do something like this:

    PHP Code:
    <?php
    // PHP magic here 
    ?>

    <!DOCTYPE HTML>
    <html>
    <head>
    <meta charset="utf-8">
    <title>My title</title>
    <link href="/styles.css" media="screen" rel="stylesheet" type="text/css" />
    </head>

    <body>

    <?php
    // More PHP magic here
    ?>

    </body>
    </html>

  3. #3
    SitePoint Member
    Join Date
    Jul 2013
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i want to to link stylesheets in a php file as i may use it in whole website

  4. #4
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    6,008
    Mentioned
    219 Post(s)
    Tagged
    12 Thread(s)
    Sorry, this still doesn't make sense.
    What do you mean "link stylesheets"?

  5. #5
    SitePoint Guru bronze trophy
    Join Date
    Feb 2013
    Posts
    772
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    As Pullo has pointed out, style sheets go in the head section of your site. Do you have a head section? Is style sheet based on "theme" or something? If so you can make a little IF statement, otherwise add it to your head section.
    PHP Code:
    <?php
    // PHP magic here 
    ?>

    <!DOCTYPE HTML>
    <html>
    <head>
    <meta charset="utf-8">
    <title>My title</title>
    <?php
        
    if($style == "style1"){
            echo 
    '<link href="/style1.css" media="screen" rel="stylesheet" type="text/css" />';    
        }else{
            echo 
    '<link href="/default.css" media="screen" rel="stylesheet" type="text/css" />';    
        }
    ?>
    </head>

    <body>

    <?php
    // More PHP magic here
    ?>

    </body>
    </html>

  6. #6
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,301
    Mentioned
    460 Post(s)
    Tagged
    8 Thread(s)
    It sounds like the aim here is to use a PHP include that pulls in the style sheet onto each page. You can do it easily like so:

    Code:
    <?php include $_SERVER["DOCUMENT_ROOT"] . "/includes/styles.php"; ?>
    In styles.php, you'd have something like this:

    Code:
    <link href="/styles/site.css" media="screen" rel="stylesheet" type="text/css" />
    Normally I place a whole bunch of things into an include that gets pulled into the <head> section, like style sheet links, favicon etc.

  7. #7
    SitePoint Member belansus's Avatar
    Join Date
    Aug 2013
    Location
    Newcastle
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Include Statements

    Just following on from ralph.m, a little snippet of what you could use with the include statements.

    PHP Code:
    @define("DOCUMENTROOT",$_SERVER["DOCUMENT_ROOT] . "/include/");
    @define("
    SITEROOT","http://www.<EXAMPLE_WEBSITE>");
    include(DOCUMENTROOT"include/header.php");
    // Main content generation
    include(DOCUMENTROOT"include/footer.php"); 

    Header.php
    PHP Code:
    <head>
    <!-- Meta -->
    <title></title>
    <meta name="description" content=" " />
    <meta name="keywords" content=" " />
    <meta name="author" content=" " />
    <!-- CSS -->
    <link href="<?=SITEROOT;?>styles/site.css" media="screen" rel="stylesheet" type="text/css" />
    </head>
    Includes require server paths..

  8. #8
    SitePoint Addict
    Join Date
    Jul 2006
    Location
    Fionnphort, Isle of Mull, Scotland
    Posts
    353
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    If your main HTML document is a template, you may wish to pull in different style sheets, depending on the content to be included further down the page. I do it by having the following in the <head>, after pulling in the basic style sheet with the usual link statement:
    PHP Code:
        <link rel="stylesheet" type="text/css" href="/css/basic.css" media="all" />
        <style type="text/css">
        <!--
    <?php
        
    if (isset($css)) {
            echo 
    "@import url(/css/" $css ");\n";
        }
        if (isset(
    $css2)) {
            echo 
    "@import url(/css/" $css2 ");\n";
        }
    ?>
        -->
        </style>
    where $css, $css2 are file names such as 'mystyle.css'.
    This allows me to import further supplementary style sheets which can be different depending on the content that follows (which might be pages with information, or tables, or forms...).
    Why have all these style sheets ? Well I find it easier to avoid conflicts that way than to keep thinking up new class names. And it keeps the style sheets short.
    Tim Dawson
    Isle of Mull, Scotland


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •