Show 'em what you got
Many sites have some sort of a consistent style, which you can think of as a template. The template is often used to display headers, ads, and navigational menus that change as users visit different sections of the site. The easiest way to maintain this template is to create a function that outputs most of the HTML used to structure the site. You can pass parameters to this function to customize the site appearance. Listing 2, shown below, is the function used to generate the page header for my example site.
Listing 2. Defining the page header
|
The $params
array lets each script that calls this function pass in data to use in Web page customization. In this example, it is only used to add navigation text to the <TITLE> tag.
Next in this example is a check to see whether the visitor is logged in. If so, he or she is greeted with a warm "Welcome back" message that includes the visitor's first name, if it was provided in the user preferences. Visitors who are logged in are also given menu selections to change their site preferences or log out. If visitors are not logged in, they see a generic greeting and the menu contains only one option, which leads to the login page.
After the visitor has been properly greeted, it is time to show some news (which is, of course, why someone would visit our site). Listing 3 contains the function used to display news headlines from a single news source.
Listing 3. Displaying news items from a single news source
|
The show_news
function is passed an integer that represents the source_id
of the news source. Next, the headline text and URL link are fetched from the database for the five most recent news items. The item limit would make a good configurable parameter if you wanted to extend this example. If the news items are found, it simply prints out an HTML list item for each item as a link to the story.
View Personalized Web sites in a jiffy Discussion
Page: 1 2 3 4 5 6 7 Next Page: Tie it together