topical media & game development

talk show tell print

professional-search-14-seophp-category.php / php



  <?php
  // load the catalog library
  require_once 'include/catalog.inc.php';
  // load the URL factory library
  require_once 'include/url_factory.inc.php';
  // load the URL redirect library
  require_once 'include/url_redirect.inc.php';
  // load pager library
  require_once 'include/simple_pager.inc.php';
  
  // retrieve the category details
  category_id = _GET['category_id'];
  categories = Categories::get(category_id);
  category = categories[0];
  category_name = category['name'];
  
  // retrieve the page number; if none is provided, assume 1
  page = isset(_GET['page']) ? _GET['page'] : 1; 
  
  // redirect to the proper URL if necessary
  proper_url = make_category_url(category['name'], category_id, page);
  fix_category_url(proper_url);
  
  // retrieve the products in the category
  products = Products::get(0, category_id);
  
  // send a 404 if the category does not exist.
  if  (!products) {
    header("HTTP/1.0 404 Not Found");
    exit();
  }
  ?>
  
  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  <html>
    <head>
      <title><?php echo category_name ?> - Cookie Ogre's Warehouse</title>
    </head>
    <body>
      <h1>
        <?php echo category_name ?> - 
        <a href="/">Cookie Ogre's Warehouse</a>
      </h1>
      Find these extraordinary products in our 
      <b><?php echo category_name ?></b> category: 
  
  <?php
  // load the URL factory
  require_once 'include/url_factory.inc.php';
  
  // display each product
  echo "<ul>";
  
  // calculate which products to display on this page
  start = (page - 1) * PRODUCTS_PER_PAGE;
  end = min (start + PRODUCTS_PER_PAGE, count(products));
  
  // display the products for the current page
  for (i = start; i < end; i++ ) 
  {
    url = make_category_product_url(category_name, category_id, 
                                     products[i]['name'], products[i]['id']);
    echo '<li>' . 
         '<a href="' . url . '"' . '>' . products[i]['name'] . '</a>' . 
         '</li>';
  }
  echo "</ul>";
  
  // 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));
  ?>
  
    </body>
  </html>
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.