External PHP file serving as a CSS sheet?

Discussion in 'PHP' started by mrShrimp, Apr 24, 2012.

  1. #1
    So I have been looking into methods that would allow me to resize the left-margin on an element in my category-archive-display-page in accordance to the size of the thumbnail image that accompanies the element I want to work with (the element is an excerpt). I found out about using a .php file as a CSS sheet, and I am confused as to how to make it work. I made a .php file, and put the link to it in my archive.php file (which controls the display of the element). What I have so far in the .php file is this:

    <?php
    header("Content-type: text/css; charset: UTF-8");
    
    echo "div.summary-content h2.posttitle, div.summary-content p.date, div.summary-content div.entry {
    margin-left:265px;}";
    
    //$thumbnailx=get_the_post_thumbnail( $size[1] );
    
    ?>
    PHP:
    The comment is what I will be using later on instead of 265, but now I am just looking for results. Is there something wrong with this code? Because there are definitely no results showing up on my website.
     
    mrShrimp, Apr 24, 2012 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    If you view the file directly in a browser does the css look correct?
     
    jestep, Apr 25, 2012 IP
  3. mrShrimp

    mrShrimp Peon

    Messages:
    24
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    No, the CSS doesn't even show up if I view it in my browser (firefox). I don't even know if I'm writing correctly, or implementing it in the right way.
     
    mrShrimp, Apr 25, 2012 IP
  4. ApocalypseXL

    ApocalypseXL Notable Member

    Messages:
    6,095
    Likes Received:
    103
    Best Answers:
    5
    Trophy Points:
    240
    #4
    Echo the fraking style tag otherwise it won't work . Also you echo a fixed value not a variable.
     
    ApocalypseXL, Apr 25, 2012 IP
  5. mrShrimp

    mrShrimp Peon

    Messages:
    24
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Sorry, I'm new to PHP and HTML, could you show me what you mean?
     
    mrShrimp, Apr 25, 2012 IP
  6. exposingfreaks

    exposingfreaks Peon

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #6
    damn i need to learn php..
     
    exposingfreaks, Apr 25, 2012 IP
  7. mrShrimp

    mrShrimp Peon

    Messages:
    24
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Even though this isn't relevent, I got an overview of HTML, CSS, and PHP at w3schools, Google it. It doesn't go into too much depth, but it's very simple.
     
    mrShrimp, Apr 25, 2012 IP
  8. ryan_uk

    ryan_uk Illustrious Member

    Messages:
    3,983
    Likes Received:
    1,022
    Best Answers:
    33
    Trophy Points:
    465
    #8
    Your header could be a problem depending upon the browser. Need more information (and you to test) to establish that. I recommend you try it in Firefox, Chrome, IE, Safari and Opera to ensure the CSS is displayed fine in all. Anyway, here's a short hand for what you could do:

    <?php
    
    header blah 
    
    ?>
    
    whatever CSS
    
    <?php 
    
    whatever PHP
    
    ?>
    Code (markup):
    Saves echoing/printing the CSS all of the time.
     
    ryan_uk, Apr 25, 2012 IP
  9. mrShrimp

    mrShrimp Peon

    Messages:
    24
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Oh, so I should just style it in the archive.php file without the external CSS sheet? I think I might have tried that already, but it won't hurt to try again.
     
    mrShrimp, Apr 25, 2012 IP
  10. mrShrimp

    mrShrimp Peon

    Messages:
    24
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #10
    I tried this...

    
    <style type="text/css">
    div.summary-content h2.posttitle, div.summary-content p.date, div.summary-content div.entry {
    margin-left:<?php echo get_the_post_thumbnail( $size[1] ); ?>px;
    }
    </style>
    
    PHP:
    ...in the archive.php file with no results. When I change it to this...

    
    <style type="text/css">
    div.summary-content h2.posttitle, div.summary-content p.date, div.summary-content div.entry {
    margin-left:265px;
    }
    </style>
    
    PHP:
    ...it puts the margin into the page. I am using the latest version of Firefox. Am I doing something wrong?

    PS: I think something got weird with the PHP tags, because they aren't displaying correctly (I think).
     
    Last edited: Apr 25, 2012
    mrShrimp, Apr 25, 2012 IP
  11. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #11
    Try this for archive.php

    <?php
    header('content-type: text/css; charset: UTF-8');
    header('cache-control: must-revalidate');
    
    echo <<<'EOD'
    div.summary-content h2.posttitle, 
    div.summary-content p.date, 
    div.summary-content div.entry {
    margin-left:265px;
    }
    EOD;
    
    ?>
    PHP:
    And in the header use:

    <link rel="stylesheet" type="text/css" media="screen" href="/css-path/archive.php" />
     
    jestep, Apr 26, 2012 IP
  12. mrShrimp

    mrShrimp Peon

    Messages:
    24
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Put that in archive.php, or the seperate .php stylesheet?
     
    mrShrimp, Apr 26, 2012 IP