Designing the blog architecture
If this is your first blog application from scratch, it should be a great experience because you're going to be able to tailor it to your own needs using a great language, PHP. Now you'll start defining the main blog page where visitors to your blog will be directed to in order to view your blog entries.
This is the first page that visitors to your blog will see. You're going to create a simple greeting, but feel free to customize it to your own wishes. Define the index.php file, as shown in Listing 3.
Listing 3. Defining the index.php file
<?php
include('includes/functions.php');
define('DIRECTORY_LISTING', "blogs");
$title="Welcome to ".BLOG_NAME;
include('header-sidebar.php');
print("<p>Welcome to ".BLOG_NAME."!<br>".
"Take a look at my latest postings on the left.");
include('footer.php');
?>
|
Notice that the constant, DIRECTORY_LISTING, defines where the blog entries will be kept. Later, you'll develop code to traverse this directory looking for blog entries. Next, you define the $title variable that will be used in the header-sidebar.php file to display the title. A simple greeting is also displayed, followed by the footer.
You'll have to wait for a preview because it doesn't look as pretty without the title, header, side panel, and footer files defined, which you'll add next.
This file is combined with the side panel and is used to display a simple title for the blog using a simple grid/table format. Begin to define the header-sidepanel.php file, as shown in Listing 4.
Listing 4. Defining the header-sidepanel.php file
<?php
print('
<html>
<title>'.$title.'</title>
<body>
<table width="650px" align="center" valign="top">
<tr><td colspan="2">
');
displayTopBar();
print('
</td></tr>
<tr><td colspan="2">
<center><h1>'.$title.'</h1></center></td></tr>');
...
|
The $title variable is available from the index.php file that include()'d this file. The displayTopBar() function takes care of the displaying of the Home link at the top of the blog that will always allow a visitor to return to the main welcome page of your blog. Define the displayTopBar() function, as shown in Listing 5.
Listing 5. Displaying the top panel
function displayTopBar(){
if(!isset($_GET['blog'])){
print("Home");
}
else{
print("<a href='index.php'>Home</a>");
}
}
|
Thus, if a blog has been selected for viewing, a link to take them back to your main welcome page will appear; otherwise, only the text Home will be displayed, without a link. This helps to not confuse visitors that first come to the page. If they clicked on Home and were taken to the same page, it would be a poor and confusing design flaw.
Let's move on to the side panel and footer, complete with a preview.
The side panel will contain links for all the visitors to your blog to view your interesting ramblings, ravings, or other discussions you might write in your blog. Finish designing the header-sidepanel.php file, as shown in Listing 6.
Listing 6. Completing the header-sidepanel.php file
...
<tr><td colspan="2">
<center><h1>'.$title.'</h1></center></td></tr>');
print('<tr><td height="100%">
<table width="150px" align="left" border="2px" height="100%">
<tr><td valign="top">
<table width="150px">
<tr>
<td><b>My Web Logs</b></td>
</tr>
<tr>
<td>');
listBlogs();
print('
</td>
</tr>
</table>
');
// add new side panel items here, using the above "My Web Logs"
// item as a template.
print('
</td></tr></table>
</td><td valign="top" width="100%">
');
?>
|
New code is noted in bold. The side panel starts off with the two <table> tags. Here, you only have one category listed in the side panel. If you wanted to add another one, you would add it as noted in the two commented lines (lines starting with //). The side panel is completed with the closing of the last </table> tag. Then it opens the main content section up with the last <td ... > tag.
Next, you'll finish up the HTML with the footer.php file.
This file completes the welcome page for your blog. Define the footer.php file, as shown in Listing 7.
Listing 7. Defining the footer.php file
</td></tr>
<tr><td align="center" colspan="2">
<font size="2px"><br>
<center>Copyright 2005, <?php print(BLOG_NAME) ?></center>
</font>
</td></tr></table>
</body></html>
|
This file also references the BLOG_NAME constant in its display of a simple copyright notice. Surely you don't want someone stealing your blog content and displaying it elsewhere on the Web without giving you credit or linking back to your site.
You can now preview the page, as shown in Figure 1.
Figure 1. The main welcome page
Now let's add some blog entries.





