Prev | Current Page 307 | Next

Emilian Balanescu and Cristian Darie

"Beginning PHP and MySQL E-Commerce: From Novice to Professional, Second Edition"


CHAPTER 7 ?–  SEARCH ENGINE OPTIMIZATION 207
Exercise: Generating Customized Page Titles
1. Open presentation/store_front.php, and add the highlighted member to the StoreFront class:
class StoreFront
{
public $mSiteUrl;
// Define the template file for the page contents
public $mContentsCell = 'first_page_contents.tpl';
// Define the template file for the categories cell
public $mCategoriesCell = 'blank.tpl';
// Page title
public $mPageTitle;
2. In the same class, StoreFront, add the following code at the end of the init() method:
// Load product details page if visiting a product
if (isset ($_GET['ProductId']))
$this->mContentsCell = 'product.tpl';
// Load the page title
$this->mPageTitle = $this->_GetPageTitle();
}
3. Continue updating the StoreFront class by adding the following private method:
// Returns the page title
private function _GetPageTitle()
{
$page_title = 'TShirtShop: ' .
'Demo Product Catalog from Beginning PHP and MySQL E-Commerce';
if (isset ($_GET['DepartmentId']) && isset ($_GET['CategoryId']))
{
$page_title = 'TShirtShop: ' .
Catalog::GetDepartmentName($_GET['DepartmentId']) . ' - ' .
Catalog::GetCategoryName($_GET['CategoryId']);
if (isset ($_GET['Page']) && ((int)$_GET['Page']) > 1)
$page_title .= ' - Page ' . ((int)$_GET['Page']);
}
elseif (isset ($_GET['DepartmentId']))
{
$page_title = 'TShirtShop: ' .


Pages:
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319