I am designing my own site. First I created a template with header.php and footer.php I put them in the includes folder. So, everytime I am going to make a new page like "about page" all I have to do is to call them using the code below:
<body>
<?php include("includes/header.php"); ?>
<?php include("includes/footer.php"); ?>
</body>
</html>
Here is the code in my header.php
<div id="headwrapper">
<header>
<div id="logo"><img src="images/adlogo.png"/></div>
<div id="homefeature">622x82</div>
<div id="nav">
<ul>
<li>Home</li>
<li>About</li>
<li>portfolio</li>
<li>Blogs</li>
<li>Contact</li>
</ul>
</div>
</header>
</div><!--end of headwrapper-->
But my index.php and my about page have the same header image. Is there a way or code that can accomplish the work for different header images for every page? Example on index.php I want to have image1 and to my about page I want to have image2. That's all thank you by the way I am not using a wordpress my site is not a wordpress.
Another solution.
In header.php you call function $_SERVER['PHP_SELF'] for get page name and then selected image for that page. You could modify like this
<?php
$imageName = "";
if($_SERVER['PHP_SELF'] == "index.php")
{
$imageName = "images/1.png";
}
elseif($_SERVER['PHP_SELF'] == "aboutus.php")
{
$imageName = "images/2.png";
}
?>
<div id="headwrapper">
<header>
<div id="logo"><img src="'".<?=$imageName?>."'"/></div>
<div id="homefeature">622x82</div>
<div id="nav">
<ul>
<li>Home</li>
<li>About</li>
<li>portfolio</li>
<li>Blogs</li>
<li>Contact</li>
</ul>
</div>
</header>
</div><!--end of headwrapper-->
Given your structure, I think you can set your header file like this:
<body>
<?php $header_image = "about_us_header.jpg"; ?>
<?php include("includes/header.php"); ?>
<?php include("includes/footer.php"); ?>
</body>
and reference the variable in your header:
<div id="headwrapper">
<header style="background: url(<?php echo $header_image; ?>);">
But wait I thought of a better way
you can do it in css like this:
<body class="aboutus">
<?php include("includes/header.php"); ?>
<?php include("includes/footer.php"); ?>
</body>
and in your css stylesheet:
body.aboutus header {
background: url(whatever.jpg);
}
Related
I have looked at prevous questions about this and people say php and have not found an answer. how do I convert my navbar to php and use it in multiple html pages. Could someone tell me how to do so? I am currently taking a codecademy course on php and it is really hard for me to understand so please be patient.
<div class="tabs">
<ul>
<a href="http://degraphic-design.dunked.com/contact-me" style="text-decoration:none">
<li class="contact">Contact</li>
</a>
<li class="dropdown">Shop</li>
<li class="forum">Forum</li>
<a href="index.html" style="text-decoration:none">
<li class="about">About</li>
</a>
<li class="team">Team</li>
<a href="http://degraphic-design.dunked.com/" style="text-decoration:none">
<li class="portfolio">Portfolio</li>
</a>
</ul>
</div>
Say you have about.php and home.php in the root of your website. Create a directory called partials (or whatever), go into partials and put the contents of your navigation HTML in a file called nav.php. Then in about.php and home.php, use this where you want to include the navigation code
<?php include 'partials/nav.php'; ?>
Here is one way (extremly basic):
Create a PHP file called index.php
<!DOCTYPE html>
<html>
<body>
<header>
<?php
include 'header.php';
/**
* say you wanted a different header for shop
* if($_GET['page'] === 'shop') {
* include 'header-shop.php';
* } else {
* include 'header.php';
*}
*/
?>
</header>
<div id="main">
<?php
include $_GET['page'].'.php'; // assuming your storing your pages in same path as index
?>
</div>
<footer>
<?php
include 'footer.php';
?>
</footer>
</body>
</html>
Then a header.php
<div class="tabs">
<ul>
<li>Contact</li>
<li>Shop</li>
</ul>
</div>
And create your page files contact.php, shop.php ect.
Updated to a slightly more elaborate example to give you the idea.
I try to use jquery pjax to load my contents in a div. this works fine, but if i reload the page i have no content. i think i need to put the page content in the else{ part, but i don't want to set the whole html in a php variable. how to fix this?
index.php:
<?php
$title = 'Home';
if(isset($_SERVER['HTTP_X_PJAX']) && $_SERVER['HTTP_X_PJAX'] == 'true'){ ?>
<div id="content">
<h1>home</h1>
</div>
<?php echo "<title>{$title}</title>";
}else{
include 'wrapper.php';
}
?>
wrapper.php:
<ul class="nav navbar-nav" style='margin-left:20px;'>
<li><a href='index.php' data-pjax='content'>Home</a></li>
<li><a href='page1.php' data-pjax='content'>Demo 1</a></li>
<li><a href='page2.php' data-pjax='content'>Demo 2</a></li>
</ul>
<div id="content"></div>
The JS:
$(document).ready(function() {
$(document).pjax('a[data-pjax]', '#content', {
fragment: '#content'
});
});
page1.php
<?php if(isset($_SERVER['HTTP_X_PJAX']) && $_SERVER['HTTP_X_PJAX'] == 'true'){ ?>
<div id="content">
<h1>Page 1</h1>
</div>
<?php } else{ include 'wrapper.php';} ?>
page2.php
<?php if(isset($_SERVER['HTTP_X_PJAX']) && $_SERVER['HTTP_X_PJAX'] == 'true'){
?>
<div id="content">
<h1>Page 2</h1>
</div>
<?php }else{
include 'wrapper.php';
}
?>
You are only including the wrapper.php when the page is requested without PJAX (== the normal way). In wrapper.php the content is empty.
In wrapper.php you should include the correct page if the request origin is not PJAX:
First of all you should rename some files. Use index.php as the main lay-out file (what you intended to do with wrapper). Add the p as query param (which can be read true $_GET in PHP) to load pages when clicking links.
Create a file home.php which will be the default page loaded in #content at index.php.
index.php
<ul class="nav navbar-nav" style='margin-left:20px;'>
<li><a href='index.php' data-pjax='content'>Home</a></li>
<li><a href='index.php?p=1' data-pjax='content'>Demo 1</a></li>
<li><a href='index.php?p=2' data-pjax='content'>Demo 2</a></li>
</ul>
<div id="content">
<?php if(!isset($_SERVER['HTTP_X_AJAX'])) {
if(!isset($_GET['p'])) {
include('home.php');
}
else {
include('page'.$_GET['p'].'.php');
}
} ?>
</div>
This is very simple example. In live applications this should be done in another way to protect the script against certain attacks.
I'm guessing you are a starter. Please take a look at CodeIgniter. It is a framework which has a lot of ready-to-use functions. It has proven to be 'easy' to learn...
I am Developing a code using php . In which I am importing two files (header.php and footer.php) in another php file index.php.
Now I want that header.php and footer.php should be fixed while scrolling horizontally. can you suggest me the code. I am using the following code
Header.php
code here
footer.php
code here
index.php
<?php include("header.php"); ?>
welcome to index file
welcome to index file
welcome to index file
<?php include("footer.php"); ?>
In this file index.php, I want that header and footer should be fixed while scrolling horizontally and others css should also not be disturbed.
try this.,
<div id="header">
<?PHP include_once('header.php');?>
</div>
<div id="wrap">
welcome to index file
</div>
<div id="footer">
<?PHP include_once('foo.php');?>
</div>
css:
#header{position:fixed;top:0px;}
#footer{position:fixed;bottom:0px;}
or
header.php
<div id ="header"></div><div id="content">
footer.php
</div><div id="footer"></div>
index.php
<?PHP include_once('header.php');?>
content here.,
<?PHP include_once('footer.php');?>
Your solucion is ok.
only i recomend use something like this:
<div id="header">
<?PHP include_once('header.php');?>
</div>
<div id="wrap">
here is my html content
</div>
<div id="footer">
<?PHP include_once('foo.php');?>
</div>
the use of include_once is for not repeat the include of some file
and with a good css obtains a excelent layout
use HTML5 and use include_once
<header>
<?PHP include_once('header.php');?>
</header>
<div id="wrap">
here is my html content
</div>
<footer>
<?PHP include_once('foo.php');?>
</footer>
Here is just a sample FIDDLE DEMO
html,body{
margin:0;padding:0;
}
header{
background:Green;
height:50px;
}
footer{
position:absolute;
width:100%;
bottom:0;
background:Red;
height:50px;
}
In your css, just put the following attribute:
position:fixed; and that should do the trick.
I have a php page that has many includes. The whole page runs fine, but for my navigation bar, it does not open any page when I click on it. Please, what is missing here. Any help will be appreciated. many thanks
Here are my codes for the includes
<div id='cssmenu'>
<ul>
<li class='active'><span>Home</span></li>
<li><span>About Us</span></li>
<li><span>Packages</span></li>
<li><span>Partners</span></li>
<li><span>Gallery</span></li>
<li class='last'><span>Contact Us</span></li>
</ul>
</div>
And here is my main page code:
<body>
<div id="wrapper">
<div>
<img src="images/banner.png" width="940" height="200" />
</div>
<?php include('includes/nav.php'); ?>
<?php include('includes/slider.php'); ?>
<?php include('includes/nav.php'); ?>
<?php include('includes/contents.php'); ?>
<?php include('includes/sidebar.php'); ?>
<?php include('includes/footer.php'); ?>
</div> <!-- End #wrapper -->
</body>
Not sure of your file structure, but try removing the '../' on all you links
Change this:
<li class='active'><span>Home</span></li>
to this:
<li class='active'><span>Home</span></li>
Take the ../ out of your path.
When you include the nav.htm to your main page it acts as if it is in the main folder
Therefore if you use '../' it won't find it.
I have an Excel Template that i use to fill in data and export that to CSV to populate the following page on my website.
http://play.mink7.com/ifocus_v4/careers.php
When i export the file in Windows i get the formatting for the new line charcter right. But when i export the same excel file from MAC i dont get the new line character.
Windows File
play.mink7.com/ifocus/win.csv
and
MAc File
play.mink7.com/ifocus/mac.csv
.
My Code
<?php
include_once("libs/csv2json/CSVParser.php");
$jsonParser = CSVParserFactory::Create("json");
$path = "uploads/jobs.csv";
//This property will use the first row to convert the results into a
//json object array
$jsonParser->IsFirstRowHeader = true;
$jobs = $jsonParser->Parse($path);
$jobs = json_decode($jobs, true);
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>iFocus - Careers</title>
<link href='http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,400,700,300' rel='stylesheet' type='text/css'>
<script src="js/modernizr.custom.34639.js"></script>
<script src="js/jquery-1.9.1.min.js"></script>
<script src="js/jquery.accordion.min.js"></script>
<link rel="stylesheet" href="css/normalize.min.css">
<link rel="stylesheet" href="css/styles.css">
</head>
<body>
<div id="header" class="wrapper">
<header class="container">
<div id="logo"><img src="img/logo.png" width="185" height="69" alt="ifocus logo"></div>
<nav id="primaryNav">
<ul>
<li>Home</li>
<li>About Us</li>
<li>Case Studies</li>
<li>Services</li>
<li>Testimonials</li>
<li><a class="active" href="careers.php">Careers</a></li>
<li>Contact Us</li>
</ul>
</nav>
<div class="clearfix"></div>
</header>
</div>
<div id="mainBody">
<div class="container">
<h3>Careers</h3>
<h4>iFocus is looking for experienced professionals in the following areas: </h4>
<p>Email your resume to jobs#ifocussystec.com</p>
<div class="active-jobs">
<?php $i = 1; ?>
<?php foreach($jobs as $j): ?>
<h3 class="accordion" id="nav-section<?php echo $i++; ?>"><?php echo $j['job_code']." - ".$j['title']; ?><span></span> </h3>
<div class="accordion-content">
<p><strong>Relevant Experience:</strong> <?php echo $j['experience']; ?></p>
<p><strong>Job Description::</strong></p>
<?php $job_desc = explode("\n", $j['job_desc']);?>
<ul>
<?php foreach($job_desc as $jd):?>
<li><?php echo $jd; ?></li>
<?php endforeach; ?>
</ul>
<p><strong>Skill Set:</strong></p>
<?php $skillsets = explode("\n", $j['skillsets']);?>
<ul>
<?php foreach($skillsets as $s):?>
<li><?php echo $s; ?></li>
<?php endforeach; ?>
</ul>
<p><strong>Key Words:</strong> <?php echo $j['keywords']; ?></p>
</div>
<?php endforeach; ?>
</div>
<div class="clearfix"></div>
</div>
</div>
<script type="text/javascript">
jQuery(document).ready(function($) {
$('.accordion').accordion({
defaultOpen: 'nav-section1',
cookieName: 'accordion_nav'
});
});
</script>
</body>
</html>
Lib Link: https://github.com/crosbymichael/php-csv-to-xml-json
i have tried using "\r\n" but it doesnt give the formating either
PHPs file functions do not reliably recognize line endings from Macs (if they use \r character, as Mac Excel does, if I recall correctly.)
You need to set auto_detect_line_endings in php.ini to true, then it will properly recognize line endings, whether they are \n, \r, or \r\n.
This setting is PHP_INI_ALL, which means that it can be set anywhere, i.e., in php.ini, in .htaccess for a particular directory, or even with ini_set, e.g., ini_set('auto_detect_line_endings', true)