Hi David
Do you have any code already written to implenet a drop down menu for categories
As an example: {link saved} - hover oevr insurance or money, then display sub categories
or hover over Categories on this site: {link saved}
Thanks
Stuart
Thanks David
Does this just go in the index.php file?
Stuart
Hi Stuart,
It can go pretty much anywhere - if you only want the drop-down on the home page then yes, index.php is the place (note the PHP tags - if the position you want to include the code is already in PHP mode then leave them out of course). Otherwise it could go in html/header.php or html/footer.php as required if you want the drop-down shown on every page as part of your design...
Cheers,
David.
--
PriceTapestry.com
Hi David,
Is there an easy way to create a menu system across separate PT installs and DBs?
Thanks,
Marc.
Hi Marc,
Such things would normally be done with a loop; where having require()'d the main include files once, you include config.php for each site to generate whatever menu options required for that installation. To extend the above example to create a drop-down box for category selection inside 3 separate installations e.g. /electronics/, /homegarden/ and /healthbeauty/ you might do something like this:
<?php
$sites = array
(
"electronics" => "Electronics",
"homegarden" => "Home and Garden",
"healthbeauty" => "Health and Beauty"
);
$docroot = "/home/example.com/public_html/";
// following just need to come from one install, doesn't matter which
require_once($docroot."electronics/includes/database.php");
foreach($sites as $folder_name => $display_name)
{
require($docroot.$folder_name."config.php");
$sql = "SELECT DISTINCT(category) FROM `".$config_databaseTablePrefix."products` WHERE category <> '' ORDER BY category";
if(database_querySelect($sql,$rows))
{
print "<form method='GET' action='".$config_baseHREF."search.php'>";
print "<select name='q' onchange='this.form.submit();'>";
print "<option>".$display_name."...</option>";
foreach($rows as $row)
{
print "<option value='category:".htmlentities($row["category"]).":'>".$row["category"]."</option>";
}
print "</select>";
print "<noscript><input type='submit' value='Go' /></noscript>";
print "</form>";
}
}
?>
Using the $docroot variable ensures that the require() statements will work wherever you insert the code within your site, e.g. it can be included within a common header in each installation for example. You can work it out by taking the Install Path as displayed on the Support Info page of one of your installations, and removing the actual installation folder from the end...
Hope this helps!
Cheers,
David.
--
PriceTapestry.com
Thanks David.
I'm getting the following error;
Parse error: syntax error, unexpected T_VARIABLE in /var/www/vhosts/...../menu.php on line 30.
With that said, how could I output just a single list, so that I can use it in the footer?
Thanks in advance.
Hi Marcus,
There was a syntax error in the $sites array which should be:
$sites = array
(
"electronics" => "Electronics",
"homegarden" => "Home and Garden",
"healthbeauty" => "Health and Beauty"
);
(corrected above)
To create a single list of links to sites, use something like:
<?php
$sites = array
(
"electronics" => "Electronics",
"homegarden" => "Home and Garden",
"healthbeauty" => "Health and Beauty"
);
foreach($sites as $folder_name => $display_name)
{
print "<a href='/".$folder_name."/'>".$display_name."</a>";
}
?>
Cheers,
David.
--
PriceTapestry.com
Hi
I'm new to pt, hope you can help me?
I want a drop down menu that uses <ul>
and <li>
elements instead of <select>
and <option>
?
Is this possible?
Thanks
Jacques
Hello Jacques, and welcome to the forum!
Sure! The following is the minimal code to create a category menu using <ul>
and <li>
:
<?php
$sql = "SELECT DISTINCT(category) FROM `".$config_databaseTablePrefix."products` WHERE category <> '' ORDER BY category";
if(database_querySelect($sql,$rows))
{
print "<ul>";
foreach($rows as $row)
{
if ($config_useRewrite)
{
$href = $config_baseHREF."category/".tapestry_hyphenate($row["category"])."/";
}
else
{
$href = $config_baseHREF."search.php?q=category:".urlencode($row["category"]);
}
print "<li><a href='".$href."'>".$row["category"]."</a></li>";
}
print "</ul>";
}
?>
Hope this helps!
Cheers,
David.
--
PriceTapestry.com
Hi David
Thank you, this helped me allot.
thanks
Jacques
Hi Stuart,
A drop-down box category navigation is straight forward - CSS can of course be used to style as required - the basic code as follows:
<?php
$sql = "SELECT DISTINCT(category) FROM `".$config_databaseTablePrefix."products` WHERE category <> '' ORDER BY category";
if(database_querySelect($sql,$rows))
{
print "<form method='GET' action='".$config_baseHREF."search.php'>";
print "<select name='q' onchange='this.form.submit();'>";
print "<option>Browse by category...</option>";
foreach($rows as $row)
{
print "<option value='category:".htmlentities($row["category"]).":'>".$row["category"]."</option>";
}
print "</select>";
print "<noscript><input type='submit' value='Go' /></noscript>";
print "</form>";
}
?>
Cheers,
David.
--
PriceTapestry.com