Wordpress: Special css for TWO Pages - php

In my blog i have two sites, that need a special css. For the site "projects" i did this:
<?php if ( is_page('projects') ) { ?>
<link rel="stylesheet" href="<?php bloginfo('stylesheet_directory'); ?>/projects.css" type="text/css" media="screen" />
<?php } else { ?>
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" />
<?php } ?>
This works like a charm.. but i also need a special css for the home..
How can i do that..? if i just put:
<?php if( is_home() ) { ?>
<link rel="stylesheet" href="<?php bloginfo('stylesheet_directory'); ?>/home.css" type="text/css" media="screen" />
<?php } ?>
Above the other code, it will not work..
The whole code i use now is:
<?php if( is_home() ) { ?>
<link rel="stylesheet" href="<?php bloginfo('stylesheet_directory'); ?>/home.css" type="text/css" media="screen" />
<?php } ?>
<?php if ( is_page('projects') ) { ?>
<link rel="stylesheet" href="<?php bloginfo('stylesheet_directory'); ?>/projects.css" type="text/css" media="screen" />
<?php } else { ?>
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" />
<?php } ?>
Thanks for your help - and sorry for my english !

You should do:
<?php if(is_front_page()) { ?>
// html code here
<?php } else if ( is_page('projects')) { ?>
// html code here
<?php } else { ?>
// html code here
<?php } ?>

Related

Change style.css by changing language in php

Does anyone know how to use condition in CSS?
I'm using PHP Script The thing is that I have 4 files with these names "style.css","style-rtl.css","bootstrap.min.css","bootstrap-rtl.min.css" that sometimes may be in RTL language.
So I want some sort of PHP code or any other solution that can detect if the language is Ar and set the direction to RTL with style-rtl.css & bootstrap-rtl.min.css , else language is En set direction to LTR and use style.css & bootstrap.min.css .
Here is some header.php code:
<!-- Bootstrap core CSS -->
<link href="<?php echo $this->config["url"] ?>/static/css/bootstrap.min.css" rel="stylesheet">
<link href="<?php echo $this->config["url"] ?>/static/css/bootstrap-rtl.min.css" rel="stylesheet">
<!-- Component CSS -->
<link rel="stylesheet" type="text/css" href="<?php echo $this->config["url"] ?>/themes/<?php echo $this->config["theme"] ?>/style.css">
<link rel="stylesheet" type="text/css" href="<?php echo $this->config["url"] ?>/themes/<?php echo $this->config["theme"] ?>/style-rtl.css">
<link rel="stylesheet" type="text/css" href="<?php echo $this->config["url"] ?>/static/css/components.min.css">
i solved this problem with :
<?PHP
if(isset($_SESSION['lang']))
{
switch($_SESSION['lang']):
case 'eng':
// LTR Style
?>
<link href="<?php echo $this->config["url"] ?>/static/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="<?php echo $this->config["url"] ?>/themes/<?php echo $this->config["theme"] ?>/style.css">
<?PHP
break;
case 'ar':
// RTL Style
?>
<link href="<?php echo $this->config["url"] ?>/static/css/bootstrap-rtl.min.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="<?php echo $this->config["url"] ?>/themes/<?php echo $this->config["theme"] ?>/style-rtl.css">
<?PHP
break;
default:
?>
<link href="<?php echo $this->config["url"] ?>/static/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="<?php echo $this->config["url"] ?>/themes/<?php echo $this->config["theme"] ?>/style.css">
<?PHP
endswitch;
}
?>

open cart 2.2 Change style.css based on language or direction

I am trying change style.css based on language or direction in open cart 2.2
I have this input:
<link type="text/css" href="view/stylesheet/stylesheet.css" rel="stylesheet" media="screen" />
i want change stylesheet.css to stylesheet-rtl.css
This is my try:
<?php $session = new Session();?>
<?php $lang = $session->data['language']; ?>
<?php if ($lang == 'ar') { ?>
<link type="text/css" href="view/stylesheet/stylesheet-rtl.css" rel="stylesheet" media="screen" />
<?php } else { ?>
<link type="text/css" href="view/stylesheet/stylesheet.css" rel="stylesheet" media="screen" />
<?php } ?>
This worked for opencart 2.0.X but not in opencart 2.2.
What changed?
if you are using OC 2.2 you can try this code
<?php $direction = $this->language->get('direction'); ?>
<?php if ($direction == 'rtl') { ?>
<link type="text/css" href="view/stylesheet/stylesheet-rtl.css" rel="stylesheet" media="screen" />
<?php } else { ?>
<link type="text/css" href="view/stylesheet/stylesheet.css" rel="stylesheet" media="screen" />
<?php } ?>

How Do I Combined These Into an If Else Statement

I need some help combining the following two if statements into a single if-else statement. I can't seem to figure out how to do it.
<?php
if ( !is_page_template('page.php')) { ?>
<link rel="stylesheet" id="theme-style" href="<?php bloginfo('template_url'); ?>/<?php echo $theme_color ?>.css"/>
<?php } ?>
<?php
if ( is_page_template('full-page-no-background.php')) { ?>
<link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/isuzu_ecommerce.css"/>
<?php } ?>
Like this?
<?php if ( !is_page_template('page.php') ) { ?>
<link rel="stylesheet" id="theme-style" href="<?php bloginfo('template_url'); ?>/<?php echo $theme_color ?>.css"/>
<?php } elseif ( is_page_template('full-page-no-background.php') ) { ?>
<link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/isuzu_ecommerce.css"/>
<?php } ?>
Basically the same, but looks much cleaner:
<?php
$template_url = get_bloginfo('template_url');
if ( !is_page_template('page.php'))
echo "<link rel='stylesheet' id='theme-style' href='$template_url/$theme_color.css'/>";
elseif ( is_page_template('full-page-no-background.php'))
echo "<link rel='stylesheet' href='$template_url/isuzu_ecommerce.css'/>";
?>

PHP How right replace element in page?

Good day.
We have test.php with next code:
<link rel="stylesheet" type="text/css" href="<?php echo STYLE_TEST1; ?>" />
<link rel="stylesheet" type="text/css" href="<?php echo STYLE_TEST2; ?>" />
<div class="container">
<p class="test">{Text}</p>
</div>
<!-- STYLE_TEST1 and STYLE_TEST2 - set in define as "/css/styletest1.css" and "/css/styletest2.css" -->
and index.php with code:
$content = file_get_contents("test.php");
$content = ereg_replace("{Text}", 'hello', $content);
echo $content;
in result we get code:
<link rel="stylesheet" type="text/css" href="<?php echo STYLE_TEST1; ?>" />
<link rel="stylesheet" type="text/css" href="<?php echo STYLE_TEST2; ?>" />
<div class="container">
<p class="test">{Text}</p>
</div>
we have problem with styles, becose echo $content; print <?php echo STYLE_TEST1; ?> and <?php echo STYLE_TEST2; ?> and not replace on values which set in define for this elements(not change on "/css/styletest1.css" and "/css/styletest2.css").
Tell me please how right make replace?
P.S.: we need that styles was include in file test.php, ie file test.php should have lines:
<link rel="stylesheet" type="text/css" href="<?php echo STYLE_TEST1; ?>" />
<link rel="stylesheet" type="text/css" href="<?php echo STYLE_TEST2; ?>" />
Thanks all for help!
This is the best decision for me on my question
function getTemplate($file) {
ob_start(); // start output buffer
include $file;
$template = ob_get_contents(); // get contents of buffer
ob_end_clean();
return $template;
}
$content = getTemplate("test.php");
$content = ereg_replace("{Text}", 'hello', $content);
echo $content;
A way to fix this is to make it a variable....
just make sure you have
define("STYLE_TEST1", "/css/styletest1.css");
define("STYLE_TEST2", "/css/styletest2.css");
test.php
<link rel="stylesheet" type="text/css" href="<?php echo STYLE_TEST1; ?>" />
<link rel="stylesheet" type="text/css" href="<?php echo STYLE_TEST2; ?>" />
<div class="container">
<p class="test">{<?=$variable?>}</p>
</div>
<!-- STYLE_TEST1 and STYLE_TEST2 - set in define as "/css/styletest1.css" and "/css/styletest2.css" -->
index.php
$variable = 'hello';
include 'test.php';
The result will be:
<link rel="stylesheet" type="text/css" href="/css/styletest1.css" />
<link rel="stylesheet" type="text/css" href="/css/styletest2.css" />
<div class="container">
<p class="test">{hello}</p>
</div>

Custom jQuery Mobile Theme won't apply Wordpress

I'm trying to apply my own Theme made with jQuery Mobile Themeroller to my Wordpress Theme. But somehow it won't apply.
Here is my header.php code
<!DOCTYPE html>
<html>
<head>
<title>
<?php
if (function_exists('is_tag') && is_tag()) {
single_tag_title("Tag Archive for ""); echo '" - '; }
elseif (is_archive()) {
wp_title(''); echo ' Archive - '; }
elseif (is_search()) {
echo 'Search for "'.wp_specialchars($s).'" - '; }
elseif (!(is_404()) && (is_single()) || (is_page())) {
wp_title(''); echo ' - '; }
elseif (is_404()) {
echo 'Not Found - '; }
if (is_home()) {
bloginfo('name'); echo ' - '; bloginfo('description'); }
else {
bloginfo('name'); }
if ($paged>1) {
echo ' - page '. $paged; }
?>
</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<link rel="apple-touch-icon-precomposed" href="<?php bloginfo('template_url'); ?>/img/icon.png" />
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="<?php bloginfo('template_url'); ?>/img/icon-ipad.png" />
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="<?php bloginfo('template_url'); ?>/img/icon-iphone4.png" />
<link rel="apple-touch-startup-image" href="<?php bloginfo('template_url'); ?>/img/splash.png" />
<link rel="apple-touch-startup-image" sizes="640x920" href="<?php bloginfo('template_url'); ?>/img/splash-iphone4.png" />
<link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo( 'stylesheet_url' ); ?>" />
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.css">
<link rel="stylesheet" href="themes/CustomTheme.min.css" />
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.js"></script>
<?php
wp_head();
?>
</head>
<body <?php body_class(); ?>>
Also tried the the custom css before the jQM CSS and the code that is given with Theme.zip when you download it at themeroller
<link rel="stylesheet" href="themes/CustomTheme.min.css" />
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.2/jquery.mobile.structure-1.4.2.min.css" />
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.js"></script>
can you see any problems why it won't apply?

Categories