JavaScript Editor Ajax software     Free javascripts 



Main Page

// constructor
function SimplePager($rows, $limit, $function_callback,
$page_number_parameter_index = 1)
{
$this->_rows = $rows;
$this->_limit = $limit;
$this->_function_callback = $function_callback;
$this->_page_number_parameter_index = $page_number_parameter_index;
$this->_max_listed_pages = 10;
$this->_previous_prompt = ‘<< back’;
$this->_next_prompt = ‘next >>’;
}
Once this library is in place, it’s fairly easy to use it, provided that the other parts of your web site are
aware of your paging feature. For example, you have a mod_rewrite rule in
.htaccess
to handle cate-
gory URLs that contain a pager parameter. The
make_category_url()
function of the URL factory also
takes an optional
$page
parameter, and uses it to add the page to the category link if
$page
is different
than 1.
The place where you use the pager is
category.php
:
// use the SimplePager library to display the pager
$simple_pager = new SimplePager($products, PRODUCTS_PER_PAGE, ‘make_category_url’);
echo $simple_pager->display($page, $products, array($category_name, $category_id));
As you see, first you need to create a
SimplePager
instance, providing as parameters the complete list
of items the page needs to display, and number of items per page, and the function that creates links to
the individual pages (in this case, that is
make_category_url
).
After creating the instance, you call its
display()
function, providing as parameters the current page,
the list of items, and the parameters to send to the function specified when creating the
SimplePager
instance. In this case,
make_category_url()
needs to know the
$category_name
and
$category_id
in order to create the category links. The page number parameter is added by your library.
The final technical aspect we need to highlight is the fact that your catalog can contain the same product
in more categories, and you can view its details with different URLs for each of those categories. As you
know, this generates duplicate content. To avoid duplicate content problems each product has a primary
category (identified by the
primary_category_id
column in the
products
table), and you eliminate
all the product URLs except the one associated with the primary category, in
robots.txt
. For example,
if you look at Figure 14-4, you’ll see that two Frosted Fortune Cookie URLs are mentioned. The third
one, which doesn’t appear there, is that of the primary category.
Summary
We hope you’ve had fun developing Cookie Ogre’s Warehouse! Even though the implemented function-
ality is very simplistic, it did demonstrate how to tie together the bits and pieces of code you met in
the previous chapters of the book. At this point your journey into the world of technical search engine
optimiza
tion is almost complete. In the next chapter you’ll meet a checklist of details to look after when
improving the search engine friendliness of an existing site.
281
Chapter 14: Case Study: Building an E-Commerce Store
c14.qxd:c14 10:46 281


JavaScript Editor Ajax software     Free javascripts