Php--> Content-only Pages - Create easy to edit php pages.

free web hosting
Free Web Hosting, No Ads > CONTRIBUTE > Tutorials

Php--> Content-only Pages - Create easy to edit php pages.

KansukeKojima
Description

Learn 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 out
Ok, 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
Cool this will heelp me for the near future biggrin.gif. Thanks a bunchie.

Reply

galexcd
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 tongue.gif

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
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
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
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
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
A nice tutotrials! Where I can read more about it?

Reply

KansukeKojima
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
I will do it later on, exams are going on!

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Similar Topics

Keywords : php, content, pages, create, easy, edit, php, pages,

  1. Simple Javascript And Password System
    How to protect your pages with password (6)
  2. 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....
  3. 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....
  4. 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....
  5. 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....
  6. 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....
  7. 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=....
  8. 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!....
  9. 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....
  10. 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....
  11. 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....
  12. 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); } ?> ....
  13. 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..."); } ?....

    1. Looking for php, content, pages, create, easy, edit, php, pages,

Searching Video's for php, content, pages, create, easy, edit, php, pages,
advertisement



Php--> Content-only Pages - Create easy to edit php pages.



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE