I have decided to build my site website from scratch, rather than using Wordpress, Magento or a bootstrap template.
I'm looking for a good guide to do so, Code Academy and w3schools are good for learning specific elements of HTML and CSS but I'm looking for a good guide for how to structure my site.
I am playing around with creating an index.php using e.g. to include all element of the page to make creating the individual pages of my site clean and more efficient that including the include for header and footer on each page.
One issue I am having is that I am struggling to understand how to include the different pages within the index.php. I have searched for this but I obviously am not finding the correct words to search for this as I'm struggling to find a decent answer. I think I need something along the lines of a wildcard so that I can say to call all html files within my pages folder so that all pages are using my index.php template.
Below is my index.php to help explain. Thanks in advance and apologies if this question is answered elsewhere on the site, I searched but did not find anyone else answering the same question!
<!DOCTYPE html>
<html>
<php include "head.html" ?>
<body>
<div class="container">
<php include "navigation.html" ?>
<div class="wrapper">
<php include pages/*.html ?>
</div>
</div>
</body>
<php include "footer.html" ?>
</html>
It looks to me like you are almost there. I am not sure of the syntax you are using works, but the code below is used in some of my sites to include a header:
<?php include('includes/header.php'); ?>
This means include the code in the file 'header.php' that is in the folder 'includes', which is on the same level as the file that is calling the code.
The result would be that the 2 files are merged in to one when the page is loaded, with the code from header.php being inserted in place of the line
<?php include('includes/header.php'); ?>
You need to pass variables in URL e.g index.php?page=home and then in your index.php file you shoud get that variable $page = $_GET['page']. Now in $page you have name of the file to include
<?php include($page.'.html') ?>
For now, I skipped security issues of that solution.
Related
Basically i have a php script that i use to log requests on my website.(ip/browser, etc) which is log.php, how can i include the log.php in my index.html so every time someone visits my website they also get "logged"? I have tried a couple of things and its way off than what i want to do.
Basically i want to include domain.com/log.php on my main page..
I tried so many things so far and nothing has worked, i think its really really simple but i can't make it work.
Any help is highly appreciated.
Sorry for my bad english, not my first language. I hope you can understand what i mean.
The include statement takes all the text/code/markup that exists in the specified file and copies it into the file that uses the include statement.
Here's an example:
<HTML>
<head></head>
<body>
<h1>Welcome to this page!</h1>
<p>Some text.</p>
<?php include ('footer.php'); ?>
</body>
</html>
You can really execute a php code in a html file, what you can do is create a php file called index.php from there create add your code 'logging' code and then render the content of your page.
example index.php
<?php
// your code for logging the request
echo <html>...</html>
?>
I'm realizing a php website and I'm trying to split all the files in a way that should give me the possibility to update them easily.
In the current structure I've:
header.php
menu.php
footer.php
These files are included in the following pages:
page1.php
page2.php
page3.php
On each one of the pages above I write specific content. At the end my urls are:
http://www.example.com/page1.php
http://www.example.com/page2.php
http://www.example.com/page3.php
But what I would like to do is to reproduce the wordpress structure that uses index.php only as output.
So, just to go more in detail, I would like to realize an index.php inside of which I'll include just one time:
header.php
menu.php
footer.php
and including the page1.php content, the page2.php content and the page3.php content. At the end I need to have as URL a permalink that says:
http://www.example.com/page1
http://www.example.com/page2
http://www.example.com/page3
I've checked on the web but seems there's nothing online useful for my needs and when I check "permalinks" users talk only of wordpress.
Could you help me please on this activity?
Tell me if my request is not so clear or I'm wrong on something.
Thanks!
Thanks to the link suggested by #nevermind I solved the issue. Below the solution...
I created a .htaccess file with inside the following code:
RewriteEngine on
RewriteRule ^page/([^/.]+)/?$ index.php?page=$1 [L]
I created an index.php file with the following code:
<html>
<head>
<title>Test Page</title>
</head>
<body>
<?php include $_GET['page'].'.php'; ?>
</body>
</html>
I uploaded the two files in the same folder (/test/) together with the file "introduction.php".
Considering I wanted to open the page "introduction.php" I pasted the following URL in the browser:
http://www.example.com/page/test/introduction
That's all! Thanks guys for your support. I hope this can help other users looking for the same solution.
page#.php will have to be like this:
<?php
include_once('header.php');
include_once('menu.php');
//body content of page#
include_once('footer.php');
?>
you will still have 3 files with the same url but the header ,footer and menu will be the same across the pages
so here is a question that I shouldn't be having so much trouble researching, but I am. Basically I want to create a webpage that loads in a header and a side bar. The header is it's own file header.php and the sidebar is leftBar.php. The following code is my index page, yet I am failing to have these pages loaded. I believe it has something to do with a lacking css page. But I have not found anything useful to help me solve this problem. What I would like to do is have the leftBar.php display its text on the left side of the page and the header.php file at the top. Below is the linked pages.
index.php
<html>
<head>
<title>junk</title>
</head>
<body>
junk
<?php
include ('styles/header.php');
include ('styles/leftBar.php');
?>
</body>
</html>
leftBar.php
<html>
left
</html>
header.php
<html>
header
</html>
In your include files, just place the code snippet that you want to appear on the page where it's included. You certainly don't want extra <html> elements (etc.) included at various places on the page.
I have a similar setup myself for the menu bar of a test site.
I think you have unnecessary brackets around your include file paths.
index.php:
<?php
include 'menu.php';
echo "$MENU";
?>
menu.php:
<?php
$MENU = '<table class="mainmenu"><tr><td>Home</td></tr><tr><td>Useful-Sites</td></tr></table>';
?>
You don't need to declare html tag for header.php and leftBar.php. A php file should start with <?php and end with ?>. Try learning php first http://w3schools.com/php/default.asp.
trouble researching?
first page of google:
http://www.w3schools.com/php/php_includes.asp
http://www.tizag.com/phpT/include.php
http://php.about.com/od/tutorials/ht/template_site.htm
http://www.tutorialspoint.com/php/php_file_inclusion.htm
Please look at these pages, and then update your question if you have to.
I’ve built an SEO platform that Works with MySQL database and outputs / Inputs to a PHP table.
I’ve made a template in wordpress that has the header and footer from the original theme, and left the body empty so I can call the application / platform.
<?php
/*
Template name: Keywords
*/
?>
<?php get_header(); ?>
<?php
include('/body_call/index.php');
?>
<?php get_footer(); ?>
I’ve tried to place the folder with all the files (body_call) in several places and called the index.php folder hoping that it fills the center of the template.
The index folder is something like this:
<html>
<div id="container">
<body id="body">
<?php include('body_call/body.php'); ?>
</body>
</div>
</html>
I know the problem is the calling part because the platform works well if it’s by its self…
And it's probably some worpress specific code that I'm missing.
Can anyone help?
Thanks,
Miguel
When you include a file from another file you are actually just including it in the file. That means you are actually in first file folder and not second. So if second file needs to include a file wich is stored somewhere else it has to be included by navigating from first file folder to it's actual path. It sounds a little tricky. So to nvigate to upper level if need you should use ../.
Anyway to avoid any confusion i would suggest to use absolute path so where ever the file is called from it will always be able to charge any file from anywhere.
Have a look at include documentation
an example could be
include(/home/user/body_call/index.php');
I know this is a basic PHP question, and I'm trying to learn the stuff. I very familiar with HTML, CSS and familiar with the CONCEPT of PHP, but not with specifics.
I have always partnered with a back end developer to accomplish this stuff and to set up wordpress sites, etc.
I'm building a very basic four or five page website (a showcase for the client's custom fishing rods: http://www.tuscaroratackle.com/index2.php). I want to call the page header (as in logo, navigation, etc., not as in the head element) dynamically from a php file, and same thing with the footer, so I don't have to rewrite all the markup on every page for these bits.
I don't intend to use a database for this site, I was just thinking I could call those two bits from another file, as you would in a wordpress setup with the header.php in the wp-content directory.
Is there an easy explanation on how to do this? (I get the basics, just looking for help on the more specific PHP calls that need to be made)
Or, if this is not an answer somebody could easy give, can you point me to a good resource to research it further?
Thx
You betcha - include and require -
using include
in your page:
<body>
<?php include 'header.php'; ?>
in your header.php
<div id="header">
<!-- content -->
<?php echo "run php stuff too"; ?>
</div>
would result in:
<body>
<div id="header">
<!-- content -->
run php stuff too
</div>
You should put the header html code in some file such as header.php and then include it with php like:
include ('header.php');
You should specify the correct path there, for example, if you put the header.php file in includes folder, you can include it like:
include ('inclues/header.php');
More Info:
http://php.net/include
Put in a separate file and use include, require or require_once.
Eg
require_once("path/to/myfile.php");
Look into PHP includes.
The way I normally do it is to create a file called includes.php with two functions header() and footer(), then call them on each page like such:
includes.php:
<?php
function header(){
echo '<div id="header">Welcome</div>';
}
function footer(){
echo '<div id="footer">Goodbye</div>';
}
?>
index.php:
<?php
include_once('includes.php');
header();
echo '<div id="content">Main page body</div>';
footer();
?>