You are here:  » Split A - Z into subpages

Support Forum



Split A - Z into subpages

Submitted by macland on Tue, 2016-11-01 08:53 in

Apologies if this has been asked before, but I have many categories and brands and would like the category/brand page to display just numbers and letters, and then when you click on fx a you go to /categories/a.php where it will then list all the categories that begins with A.

Is there a way to accomplish this?

Submitted by support on Tue, 2016-11-01 11:02

Hi,

It did several years ago, but I'll re-document here for 15/09A and working nicely with rewrite and breadcrumbs.

Firstly, create two new scripts in the top level:

brandsIndex.php

<?php
  
require("includes/common.php");
  
$atoz["items"] = array();
  
$sql "SELECT DISTINCT(UCASE(SUBSTRING(brand,1,1))) as letter FROM `".$config_databaseTablePrefix."products` ORDER BY brand";
  
database_querySelect($sql,$rows);
  
$header["title"] = translate("Brand")." A-Z";
  
$banner["breadcrumbs"] = array();
  
$banner["breadcrumbs"][] = array("title"=>translate("Brand")." A-Z","href"=>tapestry_indexHREF("brand"));
  
$banner["h2"] = "<strong>".translate("Brand")." A-Z</strong>";
  require(
"html/header.php");
  require(
"html/menu.php");
  require(
"html/searchform.php");
  require(
"html/banner.php");
  print 
"<div class='row'>";
  print 
"<div class='small-12 columns'>";
  print 
"<ul class='small-block-grid-2 medium-block-grid-4'>";
  foreach(
$rows as $row)
  {
    print 
"<li><a href='".$row["letter"]."'>".$row["letter"]."</a></li>";
  }
  print 
"</ul>";
  print 
"</div>";
  print 
"</div>";
  require(
"html/footer.php");
?>

categoriesIndex.php

<?php
  
require("includes/common.php");
  
$atoz["items"] = array();
  
$sql "SELECT DISTINCT(UCASE(SUBSTRING(category,1,1))) as letter FROM `".$config_databaseTablePrefix."products` ORDER BY category";
  
database_querySelect($sql,$rows);
  
$header["title"] = translate("Category")." A-Z";
  
$banner["breadcrumbs"] = array();
  
$banner["breadcrumbs"][] = array("title"=>translate("Category")." A-Z","href"=>tapestry_indexHREF("category"));
  
$banner["h2"] = "<strong>".translate("Category")." A-Z</strong>";
  require(
"html/header.php");
  require(
"html/menu.php");
  require(
"html/searchform.php");
  require(
"html/banner.php");
  print 
"<div class='row'>";
  print 
"<div class='small-12 columns'>";
  print 
"<ul class='small-block-grid-2 medium-block-grid-4'>";
  foreach(
$rows as $row)
  {
    print 
"<li><a href='".$row["letter"]."'>".$row["letter"]."</a></li>";
  }
  print 
"</ul>";
  print 
"</div>";
  print 
"</div>";
  require(
"html/footer.php");
?>

Next, edit brands.php and look for the following code at line 6:

  $sql = "SELECT DISTINCT(brand) as brand FROM `".$config_databaseTablePrefix."products` ORDER BY brand";

...and REPLACE with:

  $sql = "SELECT DISTINCT(brand) as brand FROM `".$config_databaseTablePrefix."products` WHERE brand LIKE '".database_safe($_GET["letter"])."%' ORDER BY brand";

And then the following code at line 29:

  $banner["breadcrumbs"][] = array("title"=>translate("Brand")." A-Z","href"=>tapestry_indexHREF("brand"));

...and REPLACE with:

  $banner["breadcrumbs"][] = array("title"=>translate("Brand")." A-Z","href"=>tapestry_indexHREF("brand"));
  $banner["breadcrumbs"][] = array("title"=>htmlspecialchars($_GET["letter"],ENT_QUOTES,$config_charset),"href"=>"#");

Then edit categories.php and look for the following code at line 70:

      $sql = "SELECT DISTINCT(category) as category FROM `".$config_databaseTablePrefix."products` ORDER BY category";

...and REPLACE with:

      $sql = "SELECT DISTINCT(category) as category FROM `".$config_databaseTablePrefix."products` WHERE category LIKE '".database_safe($_GET["letter"])."%' ORDER BY category";

And then the following code at line 66:

      $banner["breadcrumbs"][] = array("title"=>translate("Category")." A-Z","href"=>tapestry_indexHREF("category"));

...and REPLACE with:

      $banner["breadcrumbs"][] = array("title"=>translate("Category")." A-Z","href"=>tapestry_indexHREF("category"));
      $banner["breadcrumbs"][] = array("title"=>htmlspecialchars($_GET["letter"],ENT_QUOTES,$config_charset),"href"=>"#");

Finally, edit your .htaccess file and look for the category / brand rewrite rules beginning at line 15:

RewriteRule ^category/$ categories.php [L]
RewriteRule ^category/(.*)/$ categories.php?path=$1 [L,B]
RewriteRule ^category/(.*)/(.*).html$ search.php?q=category:$1:&page=$2&rewrite=1&%{QUERY_STRING} [L,B]
RewriteRule ^brand/$ brands.php
RewriteRule ^brand/(.*)/$ search.php?q=brand:$1:&rewrite=1&%{QUERY_STRING} [B,L]
RewriteRule ^brand/(.*)/(.*).html$ search.php?q=brand:$1:&page=$2&rewrite=1&%{QUERY_STRING} [B,L]

...and REPLACE with:

RewriteRule ^category/$ categoriesIndex.php [L]
RewriteRule ^category/(.*)/$ categories.php?path=$1 [L,B]
RewriteRule ^category/(.*)/(.*).html$ search.php?q=category:$1:&page=$2&rewrite=1&%{QUERY_STRING} [L,B]
RewriteRule ^category/(.)$ categories.php?letter=$1 [B,L]
RewriteRule ^brand/$ brandsIndex.php
RewriteRule ^brand/(.*)/$ search.php?q=brand:$1:&rewrite=1&%{QUERY_STRING} [B,L]
RewriteRule ^brand/(.*)/(.*).html$ search.php?q=brand:$1:&page=$2&rewrite=1&%{QUERY_STRING} [B,L]
RewriteRule ^brand/(.)$ brands.php?letter=$1 [B,L]

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by macland on Tue, 2016-11-01 11:13

You truly are a wizard, thank you very very much

Submitted by Retro135 on Wed, 2016-11-23 05:47

Works fab, but had to remove B flag in htaccess. Did one for merchants based on this.

Submitted by Retro135 on Wed, 2016-11-23 05:53

However, when I click a merchant name, it lists all merchants in dropdown menu, not just the merchant I selected. How can I fix this?

Submitted by support on Wed, 2016-11-23 08:04

Hi,

Double check that the new .htaccess section for /merchant/ is as follows...

RewriteRule ^merchant/$ merchantsIndex.php
RewriteRule ^merchant/(.*)/$ search.php?q=merchant:$1:&rewrite=1&%{QUERY_STRING} [L]
RewriteRule ^merchant/(.*)/(.*).html$ search.php?q=merchant:$1:&page=$2&rewrite=1&%{QUERY_STRING} [L]
RewriteRule ^merchant/(.)$ merchants.php?letter=$1 [L]

...i'm wondering if the query is still using category or brand if copied (2nd / 3rd lines in the above) and that is why you are seeing all merchants in the search results...

Cheers,
David.
--
PriceTapestry.com

Submitted by Retro135 on Wed, 2016-11-23 12:36

Works fine now, TY! My error, 2nd line, had q=:$1 . Only difference is on last line, I have: merchants.php.

Submitted by support on Wed, 2016-11-23 12:59

Glad you're up and running. Last line of replacement .htaccess for merchant version corrected above.

Cheers,
David.
--
PriceTapestry.com