My question is the title, and the code i have so far (in a .css file) is this: div.element1 h2.class, div.element1 p.class, div.element1 div.class { margin-left:<?php echo get_the_post_thumbnail( $size[1] ); ?>px; } What I am trying to accomplish is to resize the margin in accordance to the X factor of the post_thumbnail's size. The size is stored in an array, so I figured I could call $size[1] for the X value. Can someone help me get this fixed up? Thanks! PS: I have maybe 4 hours under the belt of reading about php and have not actually spent any substantial time working with it. This is why my question may seem newbish.
Hi mrShrimp, I wonder how too... Could a way below be legal? <link rel="stylesheet" type="text/css" href="css.php?param1=<?php echo get_the_post_thumbnail( $size[1] ); ?>" /> PHP: And then in the CSS.PHP file, this might be declared: div.element1 h2.class, div.element1 p.class, div.element1 div.class { margin-left:<?php echo $_GET['param1']; ?>px; } PHP:
On my page, this shows: " /> It's the last piece of the link tag: <link rel="stylesheet" type="text/css" href="css.php?param1=<?php echo get_the_post_thumbnail( $size[1] ); ?>" /> PHP:
My bad coding. Sorry, I was in a rush... Here's an example. This changing background color app would only accept text colors, e.g. red, blue, cyan, etc. but not #FF4411: http://www.smokingscript.com/test/v1/test.php test.php: <?php $backCol = $_POST['backCol']; if (strlen($backCol)==0) { $backCol = 'red'; } function getBackCol(){ global $backCol; return $backCol; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>test</title> <meta content="text/html; charset=utf-8" http-equiv="content-type" /> <link rel="stylesheet" type="text/css" href="css.php?param1=<?php echo getBackCol(); ?>" /> </head> <body> Hello there! <form action="test.php" method="post"> <label for="backCol">Change background to:</label> <input id="backCol" name="backCol" type="text" value="<?php echo $backCol; ?>"/> <input type="submit"/> </form> </body> </html> PHP: css.php: <?php header('Content-type: text/css'); ?> body{ background-color: <?php echo $_GET['param1']; ?>; } PHP:
Thanks a bunch, I got it to work! Something weird is still happening though. I'm using this code to get the image width: <?php $fimage_data = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), "thumbnail" ); ?> <?php $fimage_width = $fimage_data[1]; ?> <link rel="stylesheet" href="http://www.survivorsite.org/wp-content/themes/custom-community/dynamicstyle.php?param1=<?php echo $fimage_width; ?>" type="text/css" media="screen" /> PHP: Along with your code, this puts in a margin. The last standing problem is that the margin isn't actually the width of the featured image. The code seems to read the image size as its original size, a thumbnail (150x150), but somewhere along in my archive.php file I resize it. It doesn't seem to be picking up this resized image width. What can I do to fix this?
I don't know that... What did your browser's Error-Console report to you, anything that specifically related to dynamicstyle.php ? Hendra
I don't think there are any errors. I'm new to this, so I'm not exactly sure how to check for errors. I did use firebug to check for any thing in the errors section but nothing popped up, so I'm assuming the php is running fine.
Just fixed it actually. Thank you so much hdewantara! You saved me hours of reading up on php, not that I won't learn it someday though.
To me this looks like using PHP to do something that's got absolutely nothing to do with what PHP or CSS are for... I'd have to see the markup and what you are trying to do to it to truly weigh in, but as a rule of thumb if you're trying to generate CSS using a scripting language, there's either something horrifically wrong with your layout, or how that layout is being built.