Sorry had to laugh at the number of times that is in there. While a page looks to make something automatically I can guarantee those 1000's of lines of code were not made automatically. Users may think it is magic but we know better.
Something tells me you are looking to make your own site using templates.
In basic all you are doing is making a rough frame work of HTML. Then in the various areas you wish to display content you use if's and includes to bring in variables and code that will display within the predefined areas the output of said variables and code.
then make its own file name and save onto the server
Really you do not want to make a new files for each entire page you just want new files for each small segement of the page that may need to change based on when the user performs an event on (click, mouse over, ect). Reason being is a good site may have 20, 30, or even 100 possible variations on how the data could be diplayed. If you suddenly think that X element is not neded you have to go through all 20, 30, 100 pages and delete it verses just deleting it in 1 place.
So in basic how I usually handle it is, one file has the basic HTML framework it has another file that I "include' at the top of it that when a link is clicked it will determine what and were other pages should be diplayed with in that HTML framework.
As for a good place to go I guess look into the basics of building a site using php. The concept I desribe above is so basic in web design today that it gets over looked in the tutorial world yet they will assume that is how your site is layed out.