I watched the 3-part series on building a CMS site for Kailin Yong and was able to follow along with parts 1 & 2. About halfway through part 3, I got completely lost which Chris seemed to acknowledge in the audio was likely to happen.
Basically this was my perception of what was going on:
Admittedly, I don’t know much php code but from what I was able to understand, Chris was placing the opening div tags and content code in one php file and putting the closing tags in a different php file. This is where I got lost.
Can anyone point me to other resources that would explain this better? Are there books that cover this from the designer’s point-of-view? I am getting requests from clients to design sites that they can manage themselves and would like to have the option to design sites that don’t look so "bloggy."
AHH yes the old splitting of the code and using includes to bring it all back together.
Normally you would do this with big spanning divs like for example your wrapper. You would start your wrapper in your "header.php" then end it in your "footer.php" for example.
In doing this you can separate your site into sections and then pull it all back together. For example if I had a menu bar that ran through my entire 3000 page site and wanted to modify it, this would mean changing the code on 3000 pages. With an included file you are pulling the menu in from a single location to all 3000 pages, so there is really only one menu to edit, its the same for everything else too.
This also is great when you are doing dynamic PHP things with a site, because it is in a modal form you can pull in what you need to build the required page.
Now on your opening and closing tags in different files, you have to look at the bigger picture. This is that the files aren’t separate to the browser and the PHP outputs one HTML page.
So say your index.php looks like:
<?php include "header.php"; ?>
<?php include "body.php"; ?>
<?php include "sidebar.php"; ?>
<?php include "footer.php"; ?>
But would output the code that is in those files, basically printing them out.
So if you opened say your wrapper DIV in the header.php and closed it there, you would close your wrapper too soon, you need it to close after the footer (if thats how your site works) – so you would have that tag closing in the "footer.php" file.
After all this typing I bet that either makes no sense or isn’t what you were asking :D
Thanks Rob. I am starting to understand how the different php files fit together. I have to assume the original creators of WordPress had good reasons for splitting up a page into all these different php files but it seems like it would make for a debugging nightmare if an end tag is omitted or something else goes wrong in the code.
Well kind of could – but not really.
To create the files you would first create the website in its entirety, all the HTML and CSS – then you would split it into modules. So you know what code you have put into what.
If you omitted a tag, the PHP would be writing the full page anyway – so it would just be a case of using firebug to find the unclosed tag, then because you set up the files you know where that tag should go.
Wordpress go a lot more in-depth with it as they use a templating system that is 100% customisable so its probably not a good example to look at in regards to learning how the includes work.
You must be logged in to reply to this topic.