How Do I Combined These Into an If Else Statement - php

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'/>";
?>

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;
}
?>

How to create buttons that increment and decrements values in PHP Codeinginter?

for a field Balance I want to create two buttons Add and Minus Buttons. This Field shows the current balance of Reseller. So now instead to adding some values in the text box i want to add buttons to its side so that i can increment the values in that field. Also i want to add the incremented value to existing(old) value. i know there are many example over the net but didn't worked for me so please help me.
My Balance Field :
<tr>
<td>Balance</td>
<td><?php echo form_input('balance', set_value('balance', $user->balance)); ?></td>
</tr>
The Increment Decrement Buttons :
<link href="<?php echo site_url('css/bootstrap.css'); ?>" rel="stylesheet">
<link href="<?php echo site_url('css/add.css'); ?>" rel="stylesheet">
<link href="<?php echo site_url('css/datepicker.css'); ?>" rel="stylesheet">
<link href="<?php echo site_url('css/jquery-ui.css'); ?>" rel="stylesheet">
<link href="<?php echo site_url('css/jquery-ui.min.css'); ?>" rel="stylesheet">
<link href="<?php echo site_url('css/jquery-ui.structure.css'); ?>" rel="stylesheet">
<link href="<?php echo site_url('css/jquery-ui.structure.min.css'); ?>" rel="stylesheet">
<link href="<?php echo site_url('css/jquery-ui.theme.css'); ?>" rel="stylesheet">
<link href="<?php echo site_url('css/jquery-ui.theme.min.css'); ?>" rel="stylesheet">
<link href="<?php echo site_url('/bower_components/metisMenu/dist/metisMenu.min.css'); ?>" rel="stylesheet">
<link href="<?php echo site_url('/dist/css/timeline.css'); ?>" rel="stylesheet">
<link href="<?php echo site_url('/dist/css/sb-admin-2.css'); ?>" rel="stylesheet">
<link href="<?php echo site_url('/bower_components/morrisjs/morris.css'); ?>" rel="stylesheet">
<link href="<?php echo site_url('bower_components/font-awesome/css/font-awesome.min.css'); ?>" rel="stylesheet">
<link href="<?php echo site_url('bower_components/datatables-plugins/integration/bootstrap/3/dataTables.bootstrap.css'); ?>" rel="stylesheet">
<link href="<?php echo site_url('bower_components/metisMenu/dist/metisMenu.min.css'); ?>" rel="stylesheet">
<link href="<?php echo site_url('bower_components/datatables-responsive/css/dataTables.responsive.css'); ?>" rel="stylesheet">
<link href="<?php echo site_url('/bower_components/bootstrap/dist/css/bootstrap.min.css'); ?>" rel="stylesheet">
<link rel="shortcut icon" href="<?php echo site_url('img/favicon.ico'); ?>" type="image/x-icon" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
$(function()
{
$('#spinnerInput').spinner();
});
</script>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script src="<?php echo site_url('js/bootstrap.min.js'); ?>"></script>
<script src="<?php echo site_url('css/external/jquery/jquery.js'); ?>"></script>
<script src="<?php echo site_url('bower_components/metisMenu/dist/metisMenu.min.js'); ?>"></script>
<script src="<?php echo site_url('/bower_components/datatables/media/js/jquery.dataTables.min.js'); ?>"></script>
<script src="<?php echo site_url('/bower_components/datatables-plugins/integration/bootstrap/3/dataTables.bootstrap.min.js'); ?>"></script>
<script src="<?php echo site_url('/dist/js/sb-admin-2.js'); ?>"></script>
<script src="<?php echo site_url('bower_components/bootstrap/dist/js/bootstrap.min.js');?>"></script>
<script src="<?php echo site_url('bower_components/metisMenu/dist/metisMenu.min.js');?>"></script>
<script src="<?php echo site_url('bower_components/raphael/raphael-min.js');?>"></script>
<script src="<?php echo site_url('js/morris-data.js');?>"></script>
<script src="<?php echo site_url('dist/js/sb-admin-2.js');?>"></script>
<script>
$(document).ready(function() {
$('#dataTables-example').DataTable({
responsive: true
});
});
</script>
You need to add jquery-ui js and css files along with required images. Please download the files and images from below urls
JS - http://code.jquery.com/ui/1.9.2/jquery-ui.js
CSS - http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css
images -
https://code.jquery.com/ui/1.11.4/themes/smoothness/images/ui-icons_888888_256x240.png
https://code.jquery.com/ui/1.11.4/themes/smoothness/images/ui-icons_454545_256x240.png

Wordpress: Special css for TWO Pages

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 } ?>

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>

Simplifying if else statement using an array

I have my wordpress theme setting for different stylesheet selection which is set using if else statement at front end.
my wordpress setting may have one value from following pool of values
red ,green, blue, yellow, white, pink, black, grey ,silver or purple
My template :
<link href="<?php bloginfo("template_url"); ?>/style.css" rel="stylesheet" media="all" />
<?php if (get_option('my_style') == "red" : ?>
<link href="<?php bloginfo("template_url"); ?>/css/red.css" rel="stylesheet" media="all" />
<?php endif; ?>
<?php if (get_option('my_style') == "green" : ?>
<link href="<?php bloginfo("template_url"); ?>/css/green.css" rel="stylesheet" media="all" />
<?php endif; ?>
<?php if (get_option('my_style') == "blue" : ?>
<link href="<?php bloginfo("template_url"); ?>/css/blue.css" rel="stylesheet" media="all" />
<?php endif; ?>
<?php if (get_option('my_style') == "yellow" : ?>
<link href="<?php bloginfo("template_url"); ?>/css/yellow.css" rel="stylesheet" media="all" />
<?php endif; ?>
.
.
.
.
.
<?php if (get_option('my_style') == "purple" : ?>
<link href="<?php bloginfo("template_url"); ?>/css/purple.css" rel="stylesheet" media="all" />
<?php endif; ?>
In this way I can get particular stylesheet as per need. But this php code become lengthy if there are more value in the option pool. So is there any way to shorten this using an array?
May be you can reduce it to
<link href="<?php bloginfo("template_url"); ?>/css/<?php echo get_option('my_style'); ?>.css" rel="stylesheet" media="all" />
I don't think you need an array if the function get_option returns the string same as name of the css file.
This option:
<?php
$arraystyle=array("red", "green", "blue", "yellow", "white", "pink", "black", "grey", "silver", "purple");
$val=get_option('my_style');
if(!in_array($val, $arraystyle)){
echo "Style not found";
return false;
}
?>
<link href="<?php bloginfo("template_url"); ?>/css/<?php echo $arraystyle[$val];?>.css" rel="stylesheet" media="all" />
There is no real need to use an array here. You are making changes to what CSS file you are including according to a certain value.
I think what you are looking for is a switch case command. Here is a simply example of what you may be able to do with it -
<?php
$my_style = get_option('my_style');
switch($my_style){
case "red":
echo '<link href="'. bloginfo("template_url"). '/css/red.css" rel="stylesheet" media="all" />';
break;
case "green":
echo '<link href="'. bloginfo("template_url"). '/css/green.css" rel="stylesheet" media="all" />';
break;
default :
echo '<link href="'. bloginfo("template_url"). '/css/default.css" rel="stylesheet" media="all" />';
break;
}
?>
Using this method, you can include more than one change for each my_style option. Note the use of a default case to handle any unexpected values...
Reference -
switch structures
<?php
$my_styles = array(
'red',
'green',
'blue',
'yellow',
'white',
'pink',
'black',
'grey',
'silver'
);
?>
<?php if(in_array($my_style = get_option('my_style'),$my_styles)) : ?>
<link href="<?php echo bloginfo("template_url")."/css/{$my_style}.css"; ?>" rel="stylesheet" media="all" />
<?php endif; ?>
You can fill the variable with $my_styles with all the available styles, be it from database or whatever..

Categories