Hello David,
As you know i created a menu on my website. I like to show only on the index page the main categories. When i click on the a main category (for example pricetapestry) i'd like to see that categoy with his subcategories.
Can you tell me how i can make that?
Thanks,
Jan Roel
Hello i dont use hierarchy i build the category manually with menu tree where you helped me with several days ago.
Hello Jan,
You can use PHP's $_SERVER["REQUEST_URI"] variable to identify which page you are on and render a different menu for different pages, for example, to show one version of the menu on your home page, and a different version on the /category/ page, use:
<?php if ($_SERVER["REQUEST_URI"] == "/"): ?>
<!-- menu HTML for home page here -->
<?php endif;
<?php if ($_SERVER["REQUEST_URI"] == "/category/"): ?>
<!-- menu HTML for home page here -->
<?php endif;
Hope this helps!
Cheers,
David.
--
PriceTapestry.com
Hello David,
I hope you can help me. I use above code to show different menus on specific category pages.
My question:
On my indexpage i have main categories. I created these categories in the database. But i never place products under these main categories. When i click on a main category i go the page and i see the category menu belonging to this this category. Now my problem: The product section is blank because there aren't product under it. Is it possible that i add manually several categories with products which shows up when visitor i clicking on these main category? And is it possible that the 20 most viewed products from my selected categories are showed.
I have the table views in my database because i use this also on my indexpage.
$sql = "SELECT name,1 AS sequence FROM `".$config_databaseTablePrefix."products` WHERE category IN (SELECT name AS category FROM `".$config_databaseTablePrefix."categories`) ORDER BY views DESC LIMIT 24";
Thank you,
Jan Roel
Hello Jan,
The /category/ pages are generated by categories.php. If at a "leaf" node the script then calls in search.php to display the results, otherwise the list of sub-categories, which is what you are seeing is pulled in by the following code at line 101:
if (isset($atoz)) require("html/atoz.php");
At this point, the category IDs of all sub-categories is in the $nodeInfo["lowerarchy"] array, so you can use this to select products from all sub-categories, ordered by views exactly as you are doing on the home page, so where you have the above code, REPLACE with:
if (isset($atoz)) require("html/atoz.php");
$ins = array();
foreach($nodeInfo["lowerarchy"] as $id)
{
$ins = "'".database_safe($id)."'";
}
$sql = "SELECT name,1 AS sequence FROM `".$config_databaseTablePrefix."products` WHERE category_id IN (".implode(",",$ins).") ORDER BY views DESC LIMIT 24";
...and then follow that immediately by the same code you are using on your home page to execute the query (database_querySelect) and display the results...
Hope this helps!
Cheers,
David.
--
PriceTapestry.com
Hello David,
Thanks only the problem is i don't use category hierarchie mapping. I use category mapping. It's also not easy to change it because i have 3200 categories.
I use category mapping because i also the unmapped.php option. I only show categories which are mapped. I thought that wasn't possible with category hierarchy mapping.
Jan Roel
Hello Jan,
Sure - in that case, the page being rendered will actually be search.php and will be calling in html/noresults.php from line 541:
require("html/noresults.php");
So you could add to html/noresults.php something like:
<?php
if ($parts[0]=="category")
{
$in["Main Category 1"] = "'Category A','Category B','Category C'";
$in["Main Category 2"] = "'Category D','Category E','Category F'";
$in["Main Category 3"] = "'Category G','Category H','Category I'";
if (isset($in[$parts[1]]))
{
$sql = "SELECT name,1 AS sequence FROM `".$config_databaseTablePrefix."products` WHERE category IN (".$in[$parts[1]].") ORDER BY views DESC LIMIT 24";
<!-- database_querySelect(..) and display code here -->
}
}
?>
Edit the $in array with your Main Category names and the existing categories you want to include as required, and as per the above, replace the comment
<!-- database_querySelect(..) and display code here -->
...with the existing query execution and display code that you are using on home page...
Hope this helps!
Cheers,
David.
--
PriceTapestry.com
Hello David,
I made it like this but nothing show up on this page:
<?php
if ($parts[0]=="category")
{
$in["Baby-en-peuter"] = "'Babyslofjes','Flessenwarmers'";
if (isset($in[$parts[1]]))
{
$sql = "SELECT name,1 AS sequence FROM `".$config_databaseTablePrefix."products` WHERE category IN (".$in[$parts[1]].") ORDER BY views DESC LIMIT 24";
if (database_querySelect($sql,$rows))
{
$sqlNames = array();
$sqlCase = "CASE normalised_name";
foreach($rows as $featured)
{
$featured["name"] = tapestry_normalise($featured["name"]);
$sqlNames[] = "'".$featured["name"]."'";
$sqlCase .= " WHEN '".database_safe($featured["name"])."' THEN ".$featured["sequence"];
}
$sqlCase .= " END AS sequence";
$sqlIn = implode(",",$sqlNames);
$sql = "SELECT * , MIN( price ) AS minPrice, MAX( price ) AS maxPrice, COUNT( id ) AS numMerchants, ".$sqlCase." FROM `".$config_databaseTablePrefix."products` WHERE normalised_name IN (".$sqlIn.") GROUP BY normalised_name ORDER BY sequence";
database_querySelect($sql,$rows);
$featured["products"] = $rows;
foreach($featured["products"] as $k => $product)
{
$featured["products"][$k]["productHREF"] = tapestry_productHREF($product);
$featured["products"][$k]["reviewHREF"] = tapestry_reviewHREF($product);
}
}
}
}
?>
Hello Jan,
Nearly there - just missing the call to require html/featured.php - add at the end of the PHP section:
if (isset($featured)) require("html/featured.php");
Cheers,
David.
--
PriceTapestry.com
Hello David,
I allready placed this line on this place:
{code saved}
On both places nothing show up.
Jan Roel
Hello Jan,
The first location is correct, but I noticed that your main category name includes hyphen character - they would actually be removed by the normalisation at this point in the code - have a go with:
$in["Baby en peuter"] = "'Babyslofjes','Flessenwarmers'";
Hope this helps!
Cheers,
David.
--
PriceTapestry.com
Hello Jan,
Even if using Category Hierarchy, the /category/ index still works, so you can make your home page links go to, for example;
http://www.example.com/category/Main-Category/
...and that page will show all the sub-categories of Main Category. Apologies if mis-understood, let me know if you're still not sure of course...
Cheers,
David.
--
PriceTapestry.com