We??™ll not belabor on the details, as the code is pretty much straightforward.
Updating Catalog Pagination
Just as search engines assume that pages that are not linked well from external sources are less
important than those that are, they may make the assumption that pages buried within a web
site??™s internal link structure are not very important.
Our current system for navigating pages of products is a perfect example of burying pages
down the link hierarchy. To navigate between product pages, we currently only offer Previous
and Next links. This doesn??™t make it easy for visitors to navigate directly to the various product
pages, and it doesn??™t make it any easier for search engines either.
Consider the example of the fourth page of products in the Regional category. Currently,
that page can be reached by humans or by search engines like this:
Home -> Regional -> Page 2 -> Page 3 -> Page 4
The fourth page of products is harder to reach not only by humans (who need to click at
least four times), but also by search engines. Let??™s fix this problem by going through a short
exercise.
Exercise: SEO Pagination
1. In the ProductsList class from the presentation/products_list.php file, modify the init()
method of the ProductList class as shown:
/* If there are subpages of products, display navigation
controls */
if ($this->mrTotalPages > 1)
{
// Build the Next link
if ($this->mPage < $this->mrTotalPages)
{
if (isset($this->_mCategoryId))
$this->mLinkToNextPage =
Link::ToCategory($this->_mDepartmentId, $this->_mCategoryId,
$this->mPage + 1);
elseif (isset($this->_mDepartmentId))
$this->mLinkToNextPage =
Link::ToDepartment($this->_mDepartmentId, $this->mPage + 1);
}
CHAPTER 7 ?– SEARCH ENGINE OPTIMIZATION 210
// Build the Previous link
if ($this->mPage > 1)
{
if (isset($this->_mCategoryId))
$this->mLinkToPreviousPage =
Link::ToCategory($this->_mDepartmentId, $this->_mCategoryId,
$this->mPage - 1);
elseif (isset($this->_mDepartmentId))
$this->mLinkToPreviousPage =
Link::ToDepartment($this->_mDepartmentId, $this->mPage - 1);
}
// Build the pages links
for ($i = 1; $i <= $this->mrTotalPages; $i++)
if (isset($this->_mCategoryId))
$this->mProductListPages[] =
Link::ToCategory($this->_mDepartmentId, $this->_mCategoryId, $i);
elseif (isset($this->_mDepartmentId))
$this->mProductListPages[] =
Link::ToDepartment($this->_mDepartmentId, $i);
else
$this->mProductListPages[] = Link::ToIndex($i);
}
2.
Pages:
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321