HiveBrain v1.2.0
Get Started
← Back to all entries
patternphpModerate

Review structure of PHP/HTML

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
phphtmlreviewstructure

Problem

I am very new to PHP and I kind of sort of want to create the pages like I would in ASP.NET; it's just the way I am wired. I have been inserting the header/menu using a PHP Include and here is what the code looks like for just the first page.

Am I doing this properly, or is there a better way?

index.php


  
    
    New Jerusalem
    
  
  
    
      
        
      
    
      Sturgis Hellfighters
        
          Scripture Corner
          
          

        
        
          
          
        
      
    
  


Menu.php


    Home
    News
        
            Sturgis Current Events
            Rapid City Events
            Pierre Events
            Other Events
        
    
    Photos
        
            Christmas On Pine Ridge
            Christmas At the Mission
            Open House
            Nationals
        

    
    Events
         
            A Pine Ridge Christmas
            A Sturgis HellFighter Christmas
            Sturgis Motorcycle Rally
            Random City Swap Meet
            Cool Event
           
    
    Contact Info
        
            President
            Vice-President
            Preacher Man
        
        


I would like to use HTML5 if possible, so if your review brings up HTML5 that is cool with me too.

If you would like to see the front page, click here.

This page will be changing as I am currently working on it.

Solution

Going to some HTML5 stuff straight away.

-
Replace your doctype with the HTML5 doctype. This is necessary for the next few steps



-
Use the shorter charset meta tag and the meta viewport tag inside your head area. The viewport meta tag is necessary for mobile devices and ensures a good default viewport.



Side note: You may omit the type-attribute for style, script and link tag (not for RSS) and the closing / for self-closing tags. This is not a recommendation, but it's possible.

-
Use ID's only when you definitely can say "There will be only one element of this per page, ever". A wrapper is not unique to a page. It should be a class.

Generally speaking, ID's don't provide you with a true benefit and kinda makes your life harder. I don't use ID's as styling hooks anymore and I'm really happy with it.

-
You're navigation is included with PHP and is named menu.php, but it actually contains a header image as well. A better name would be header.php, wouldn't it?

That being said, you may consider moving everything above your header and the header itself to a header.php. Even your head area and the html tag. This is only usable, if you your header is the same on all of your pages.

-
I'm using dash-delmited class names in my HTML. No CamelCase names. This is my preference and if you want to use CamelCase, this is fine. However I would avoid using no delimiting and lowercase names like indexright or smallheader.

That's it for now. I'll going to edit some more stuff later. Stay tuned.

Code Snippets

<!DOCTYPE html>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

Context

StackExchange Code Review Q#40688, answer score: 11

Revisions (0)

No revisions yet.