PHP inside CSS stylesheet - php

I am trying to insert a shortcode inside CSS file but i am unable to achieve it. Don't know where I am going wrong.
I am inserting below code inside my style.css file:
div#cuzd-dispatch-general-v {
display: <?php echo do_shortcode('[dispatch_date_hide]'); ?> ;
}
OUTPUT:
div#cuzd-dispatch-general-v {
display: <?php echo do_shortcode('[dispatch_date_hide]');
}
Output as Image: http://oi61.tinypic.com/2uiyd4x.jpg

add this code in your header.php inside <style> </style>
div#cuzd-dispatch-general-v {
display: <?php echo do_shortcode('[dispatch_date_hide]'); ?> ;
}

PHP code cannot be interpreted inside a .css file so your php code will be showen as a plain text, add the part of your code in the style tag of your php file.

Related

Is it possible to each php in like css code?

I want to include a php script in a css file:
<?php
$str = "5px";
echo $str;
?>
and then
.header {
font-size: $str;
}
Is it possible?
No, not like that. CSS isn't a programming language, and has NOTHING to do with PHP.
You can, however, have PHP generate the CSS:
html:
<link rel="stylesheet" href="foo.php" ... />
foo.php
<?php
header('Content-type: text/css');
$str = '5px';
?>
.header {
font-size: '<?php echo $str; ?>';
}
Note that since you'r GENERATING css, you have to make absolutely SURE that whatever PHP outputs will be valid for the context the output is going into. It is very easy to output something that'll be a CSS syntax error and kill the rest of the CSS file.

How to add style to a php snippet

In my wordpress site I have
<?php wp_loginout(); ?>
which produces
Log in
I want to add the following style to the a tag
style="color:white;"
I don't know php. Would I try find the php and then add it somehow? And how would I add it to the php?
Use below code:-
<div id='anchorStyle'> <!-- define div -->
<?php wp_loginout(); ?>
</div>
CSS
#anchorStyle a{
color:white;
}
Hope it will help you :)
wp_loginout() has a filter hook 'loginout' which you could use to influence the output.
Add a filter function to functions.php of your theme:
add_filter('loginout', 'loginout_selector');
function loginout_selector($text) {
$selector = 'class="woo-sc-button"';
$text = str_replace('<a ', '<a '.$selector, $text);
return $text;
}
Ref: http://codex.wordpress.org/Function_Reference/wp_loginout
In functions.php replace/add this filter
add_filter( 'wp_nav_menu_secondary_items','wpsites_loginout_menu_link' );
function wpsites_loginout_menu_link( $menu ) {
$loginout = '<li class="myNewClass">' . wp_loginout($_SERVER['REQUEST_URI'], false ) . '</li>';
$menu .= $loginout;
return $menu;
}
fore reference: http://codex.wordpress.org/Function_Reference/wp_loginout
you can't style the php. The a tag is the tag you should style (html).
if you want to add your style to the a tag best practice is to find/create the file which has extension .css or create a file called (name).css
Simple way to style all your a tags is
a {
color: white;
}
Again, this styles all a tags and I don't know the entire code.
If you would want to specify which a tag gets which colors. Read up on CSS and adding class/id or nested elements.

Zend Framework: changing color of string in view

I want to set color for specific string in ZendFrame work, is it the best way?
View:
.not-found{color : red;}
<?php
echo '<div class="not-found">';
echo $this->not_found;
echo '</div>';
?>
Controller:
$this->view->not_found='no result';
Yes this is correct just wrap your css code within css html markup
If you want your css to work it needs to be in a css file linked to the view or in a style like :
<style>
.not-found{color : red;}
</style>

Style -CSS a php session value

How to style php output?
Here is an code for example?
I can only style with css the code who is in the echo.How to style the session value?
echo "<h1>Logged in as:</h1>" .$_SESSION['myusername'];
Any tip?
You can use span tag to format text inside h1 tag :
echo "<h1 class='yourClass'>Logged in as:<span class='spanclass'>" .$_SESSION['myusername']. "</span></h1>"
CSS class (for example):
.spanclass{
color:green;
}
Use class to you html in php and add a style to your css file
In css page
.yourClass{
//add your style
}
In PHP
echo "<h1 class='yourClass'>Logged in as:</h1>" .$_SESSION['myusername'];

PHP in CSS - "If page is in this directory, echo this"

I have several sites on the same hosting package. They’re all in different directories. ( i.e. “htdocs/site1”). I want to be able to have them all share one CSS file.
I was wondering if there is a way to change the color of certain elements based on which directory the site is in.
Ideally I would like to be able to define what directory the page is in and what color to use for each directory. Then in my CSS do something like:
.button { color: <?php echo $color ?> ;}
to each element that gets a color change.
Is this possible and if so, how do I go about setting this up?
thank you
You could add different classes to your body tag depending on the directory:
<body class="<?php echo $dir; ?>">
where the $dir variable is given a different value (let's say $dir = 'site1',...) for each directory...
... And then have something like:
.site1 #button { /*styles*/ }
.site2 #button { /*styles*/ }
.site3 #button { /*styles*/ }
in your CSS file.
You could add a CSS class to the body tag of the HTML document to determine the site. In PHP you would have to find a way to write the correct site into to the document. Do you use some kind of global template?
Just to give you an idea:
PHP:
<?php
// some code
// some logic to determine which site you are on - let's say ...
$site = 'SITE1';
?><body class="<?php echo $site; ?>"><?php
// more code
?>
CSS:
body.SITE1 #button { color: #ff0000; }
body.SITE2 #button { color: #0000ff; }
body.SITE2 #button { color: #123456; }
You could dynamically generate the css file using php, where you'd have
<?php
switch ($_SERVER['SERVER_NAME']) {
case 'www.site1.com':
$color = '#ff0000';
break;
case 'www.site2.com':
$color = '...';
break;
...
default:
$color = '...';
?>
.someclass { color : <?php echo $color ?>; }
This is somewhat inefficient, however. You'd be building a css file just to change a single color each time. Better way is to simply embed the color change in the page's header as an in-line style. That way you don't have to mess with making your server parse CSS files as if they were PHP scripts, and you can put the site-specific css overrides into that inline style in the site's header.
Honestly, I would suggest you add a class to your html tag:
<html class="site1">
And within your CSS, define your css:
.site1 * .button1{ background:#f00;}
.site2 * .button1{ background:#f0f;}
.site3 * .button1{ background:#ff0;}
You can find some more information on this subject here for a PHP approach.

Categories