KansukeKojima
Mar 13 2008, 09:21 PM
DescriptionLearn to create easy to edit content-only pages with php. By parsing your layout into your pages, you can reduce file sizes and files will become much neater. Try it outOk, lets start by creating a file called template.php. CODE <?php //--------------------------------- //Layout top section //--------------------------------- $top = <<< html <!-- include HTML header code here --> <body> INSERT CODE FOR [b]TOP[/b] OF LAYOUT HERE. html;
//--------------------------------- //Layout bottom section //--------------------------------- $bottom = <<< html INSERT CODE FOR [b]BOTTOM[/b] OF LAYOUT HERE. </body> html; ?> Ok simple enough. We created two variables. $top represents the top part of the layout. This should include all the code that would go over top the content on a regular page. $bottom represents the bottom part of the layout. This should include all the code that would go underneath the content on a regular page. Now for part two! Here is where the "content-only" file comes into play. Create a new file named index.php (or whatever page you want). Make it look similar to the following. CODE <html> <?php include ("template.php"); echo $top; ?> Put your content here!!! <?php echo $bottom; ?> </html> Congratualations! You now have "content-only" pages! (I'll be honest.. theres a little php... lol) You can create small, neat, tidy, and easy to edit files!
Reply
flashy
Mar 14 2008, 07:14 AM
Cool this will heelp me for the near future  . Thanks a bunchie.
Reply
galexcd
Mar 15 2008, 05:58 AM
Very good tutorial, but do you mind if I make a slight modification which in my opinion would make the code even better? If you use functions, not only can you write the code in pure html, (not using heredoc), but you can use FUNCTIONS, which are always way cooler looking than no functions  For your template file: CODE <? function top(){ ?> <!-- include HTML header code here --> <html> <body> INSERT CODE FOR [b]TOP[/b] OF LAYOUT HERE. <? } function bottom(){ ?> INSERT CODE FOR [b]BOTTOM[/b] OF LAYOUT HERE. </body></html> <? } ?> And the actual page: CODE <? include"template.php"; top(); ?> Put your content here!!! <? bottom(); ?> There are a couple reasons I prefer this method. First of all I've never been too much of a fan of heredoc, mainly because my code color coder doesn't color code html in the heredoc (which is super useful, trust me), but there are some other reasons. It just feels messy. An advantage to using functions is that you could pass data to the layout from the content page, such as the title of the page, or perhaps changes in the navigation on certain pages of your website. Now I'm not saying mine is actually better, or more efficient in any way, its just in MY opinion, I like it better, and it would be the way I would do it. I am giving our members another option to choose from.
Reply
KansukeKojima
Mar 15 2008, 09:58 PM
Thanks for your input man... I'm not to familiar with functions... unfortuneately.. Me and coolcat are using this method for our upcoming gfx site... hmm... I'm definately liking this whole function idea though.. I might have to go in and use that instead of what I was using before...
Reply
tricky77puzzle
Mar 15 2008, 11:04 PM
QUOTE(KansukeKojima @ Mar 15 2008, 05:58 PM)  Thanks for your input man... I'm not to familiar with functions... unfortuneately..
Me and coolcat are using this method for our upcoming gfx site... hmm... I'm definately liking this whole function idea though.. I might have to go in and use that instead of what I was using before... Wow, this is exactly what I wanted. Thanks, Kansuke! I wonder if you wrote this as a response to my topic about the includes.
Reply
jlhaslip
Mar 15 2008, 11:05 PM
Functions are good. The best thing about the use of functions is that you only need to 'call' them and they happen. It saves copying a lot of code into the text files, etc. Simply make the function call, and be sure your page can find the function in the "included" file. Typically, you would "include" the function file, which contains all the functions you might use in a page, at the top of each page you build.
Reply
sonesay
Mar 15 2008, 11:15 PM
The way I would do this is have all your entire layout as one file. e.g html > /html Then pass $vars to the template for each section, $title, $nav, $content, etc. That way page is always consistent and you only need to update your template to reflect changes across all pages. Another advantage is when it comes to debugging your layout its much easier if its all in one template rather then across different files. If you already are happy with the layout and no longer need to change it it may or may not be easier to update if all sections are broken up into individual files. It may just be personal preference but I find having my whole template in one file makes it easier to update and change since my layouts done in HTML and CSS and its all there. I dont know maybe you guys find it easier if its broken up like header, content, footer files. Think about it if you had to restructure the layout would it be easier to try and do it with 3 different files? I just wanted to add thats how I do mine. its personal preference I guess.
Reply
alex1985
Mar 25 2008, 04:24 AM
A nice tutotrials! Where I can read more about it?
Reply
KansukeKojima
Mar 25 2008, 03:02 PM
Well.. uh.... if you really need more info on it.... you can just ask me stuff via pm and I'll see what I can do... or you can just google for related information.
Reply
alex1985
Mar 26 2008, 03:43 AM
I will do it later on, exams are going on!
Reply
Similar Topics
Keywords : php, content, pages, create, easy, edit, php, pages,
- Simple Javascript And Password System
How to protect your pages with password (6)
Do You Want To Use Php Code In Your Html Pages?
Within two minutes you will! (9) Whilst searching around for help to setup cutenews blog I came across a way to use php in html pages
- lo and behold it works! so I thought I'd share it with you all (Unfortunately I can't
remember the site so I wrote this up a couple of minutes after I did it:) ). This method requires a
web server with apache installed. So, luckily for us all this covers the whole of Trap17... even
Qupis /tongue.gif" style="vertical-align:middle" emoid=":P" border="0" alt="tongue.gif" /> Just
to make the point, this is in no way a difficult task and it doesn't requir....
Document Type Declarations
And why we use them in html pages (0) This code: CODE <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd"> <html> <head>
<title>HTML 4.0 Strict document</title> <meta
http-equiv="content-type" content="text/html;charset=utf-8" > <meta
http-equiv="Content-Style-Type" content="text/css" > </head>
<body> <p>... Your HTML content here ...</p> <p>... More
HTML content here ...</p> </b....
Making A Dynamic Page On Blogspot
Using an external server to make your pages hosted on blogspot dynamic (5) Good morning everyone. Have you ever wondered how to allow your visitors to edit content on your
blog? Like adding a post straight off the page, adding a link, editing your profile etc. This will
be extremely useful if you want your visitors to contribute to your blog besides writing comments or
tagging. 1. Adding a post straight off the page. Go to blogger.com, login, select your blog. Go to
settings -> email. By enabling blog email, you can now add a post by simply sending an email to the
address you specified. The address should look something like: yourusername....
How To: Make A Simple Php Site
Making one file show up on all pages using php (21) I have looked all over the site and could not find anything that was like this simple, or just like
this at all.. For some people i know that you are using a basic HTML site...and having a big menu
if you want to add somthing you have to go into every one of the pages and add or remove or edit
what you want to do, but with somthing verry simple all you would have to do is edit one file, and
all of the pages that have the PHP script on them would suddenly change to what that one file is.
So to start off if you are planning on using this little tirck, the page that you a....
Getting Content To Blog About
Good for bloggers and content-rich sites (0) There are many ways to build content for your blog. I am just sharing some ways that I have
personally used to build content-rich blog for my company. (http://blogasia.biz) While I am trying
my best to provide as much information as possible, these are not all the ways to do it. I am merely
sepeking from the point of a 4 month old blogger. So if you have anything to add to this thread
please feel free to do so. 1) Feeds. Also commonly known as RSS / XML / Syndication etc. What
ever it is .. these are merely ways of grabbing information from a website / blog that have....
How To Edit Your "index Page"
Adding new pages? (0) This tutorial was requested by sxyloverboy . Introduction: sxyloverboy has asked me how
to make your navigation bar on him website change to add another page, without having to do it on
every page. Well, I have the answer for you! Beginning Assuming you have a FTP upload
access, you'll be open your file "index.php" -=Example=- Once your "index.php" file is open
press "CRTL+F" (Find) and search for something that looks like this; CODE
<tr> <td class="off" onmouseover=....
Custom 404 Error Pages
A Tutorial On How To Make Custom 404 Error Pages (17) I've seen a tutorial on here and no offense but it was horrific, this is the real way you do a
404 Error Page. Make a file called: htaccess.txt Open it up and put this: CODE ErrorDocument
404 /myerrorpage.html You will need to change myerrorpage.html to whatever your page is called.
Also when you upload this file to your server you need to rename it to: .htaccess Yes, the dot is
before the words. You need to do this on the server because on Windows you cannot do that!....
How To Block Google Web Accelerator
from caching your pages (6) This only applies to your site, I don't know how I'm going to protect my email; I'm
using gmail. This sucks big-time. Anyway. This is how you do it. If you have an existing .htaccess
file in your root, add this to it: CODE RewriteBase / RewriteCond %{REMOTE_ADDR} ^72.14.192.
RewriteCond %{REQUEST_URI} !^/gwa-forbidden.html$ RewriteRule ^.*$ /gwa-forbidden.html
This is, of course, assuming you have RewriteEngine On . If you don't have it on, use
this: CODE RewriteEngine on RewriteBase / RewriteCond %{REMOTE_ADDR} ^72.14.192....
Test Your Php Pages W/o Upload/internet
complete *working* guide on how to test your php pages (57) In this tutorial, I'm going to show you how to test your PHP pages without the Internet or
uploading the files to your trap17 server. This tutorial is similar to doom's, but the links he
provided does not work, so I decided to make my own tutorial with working links. The program that I
will be using for this tutorial is called XAMPP . XAMPP is a modification of the popular Apache
server, and I'm using XAMPP because of its simplicity to install as well as maintain. The
current version of XAMPP is 1.4.13 and it has the following bundled in the download: QUOT....
All About Mambo!
Mambo is a Content Management System... (4) Mambo is the best CMS. I have written about it in many other posts elsewhere. I am not going to
write about it's pros and cons. However, this tutorial will tell you how to install and
maintain this smooth CMS. Just in case you are wondering what is CMS, it is the acronym for
Content Management System. To get a fel of how it looks and what can be done with Mambo, check out
my site . There are many other beautiful websites that have ben created with Mambo and I will write
about them later. How to install: You must have a host with PHP and MySQL facilities. If yo....
Secure Dynamic Pages Ii
(0) Just put the following code in every begining of your PHP script: CODE <?php
error_reporting("0"); ?> So, you will never see any errors. OR CODE
<?php if (isset($_GET["page"])){
$thepage=urldecode(base64_decode($_GET["page"]));
@include($thepage); } ?> ....
Secure Dynamic Pages
Another good php tutorial. (7) Hello all, Recently a friend of mine gave me this code to make your site completley dynamic and
secure at the same time. Here is what you have to do. Open a new page in your text editor and paste
in this code. CODE <?php error_reporting (E_ALL ^ E_NOTICE);
if(!$page){ $page = $HTTP_GET_VARS['page']; }
if($page=="" or $page=="main"){
include("main.php"); } if($page=""){ die("You
cannot access this page directly..."); } ?....
Looking for php, content, pages, create, easy, edit, php, pages,
|
|
Searching Video's for php, content, pages, create, easy, edit, php, pages,
|
advertisement
|
|