Is there an easy way to set up a navigation bar to browse categories? I would want this to appear above the category listing - in a similar way to the one that appears above the product listing, so you can click on the next and previous categories.
I have searched the admin facility, wiki and this forum and don't seem to be able to find reference to such a feature. Is that because there isn't one??
How many categories do you have? Dozens? Unless you have too many to fit across the top of your page, you can use the Categories-Tabs menu in a similar fashion.
If you must have a prev/next function, you will need to code it. Probably best to start by looking at how the product prev/next functions.
Many thanks for the info. There wont be that many categories, so perhaps I will look at the categories tabs. It was actually a specific request from a client.
I ended up coding my own solution for this issue. I've copied the code below. I saved it as tpl_categories_next_previous.php in my installation and called it from tpl_index_product_list.php in the same way tpl_products_next_previous.php is called from tpl_product_info_display.php in the standard installation.
I needed a quick solution here (site needs to be online by the end of May) so I apologise if this code doesn't make used of existing database classes and global variables within zen cart, I just didn't have the time to work out how to access these. Perhaps when I am more familiar with Zen internal workings I will improve this code and upload it as a plugin?
Anyway it works very well for my site, I have a happy client and am on schedule for the end of May. Here it is for anyone who might make use of it...
[php]<?php
## my plugin : does next /previous for categories
## current category / top cat
$tame_cats = explode("_",$_GET['cPath']);
$tame_top_cat = $tame_cats[0];
$tame_this_cat = $tame_cats[1];
$query = "SELECT * FROM my_mysql_database.zen_categories where parent_ID=$tame_top_cat and categories_status = 1 order by sort_order";
$result = mysql_query($query);
$i = 0;
$tame_cat_data = array();
while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
foreach($row as $key => $value) {
$tame_cat_data[$key][$i] = $value;
}
$i++;
}
foreach($tame_cat_data['categories_id'] as $key => $value) {
if($value = $tame_this_cat) $tame_this_key = $key; ## so we know which cat we have
}
$tame_last_cat_key = $key;
## do prev cat
if($tame_cat_data['categories_id'][0] != $tame_this_cat) { ## ie don't do it if it is the first cat
$tame_prev = $tame_this_cat - 1;
}
## do next cat
if($tame_cat_data['categories_id'][$tame_last_cat_key] != $tame_this_cat) { ## ie don't do it if it is the last cat
$tame_next = $tame_this_cat + 1;
}
?>
<div class="navNextPrevWrapper centeredContent">
I am not sure I am likely to be in a position to upload this as a plugin in the near future. However, I will try and help you implement the code on your site.
Lets see if I can give you some more specific instructions. but NB please back up all your files before making any of these changes so if there are any problems you can just restore the original files. I will not be held responsible for breaking your site!
First of all you need to have two files in your site.co.uk/includes/templates/my_template/templates
directory:
tpl_index_product_list.php and
tpl_categories_next_previous.php
where my_template is the name of the template your site is currently using - it might be "classic" if you are using the standard installation template.
If these files are not there do this:
1) copy the standard version of tpl_index_product_list.php from the default_template directory:
site.co.uk/includes/templates/default_templates/templates
and put it in to
site.co.uk/includes/templates/my_template/templates
2) create a new file called tpl_categories_next_previous.php and put it in the directory as above. Cut and paste the code from my second code posting into this new file and save it.
Now you need to make some changes to tpl_index_product_list.php in order for it to call the code in tpl_categories_next_previous.php:
In the file includes/templates/my_template/templates/tpl_index_product_list.php
go to line 85 or there abouts and you should see code that looks like this:
<?php
/**
* require the code for listing products
*/
require($template->get_template_dir('tpl_modules_product_listing.php', DIR_WS_TEMPLATE, $current_page_base,'templates'). '/' . 'tpl_modules_product_listing.php');
?>[/php]You need to insert this code
[php]<!--bof tame_cat prev next -->
<?php require($template->get_template_dir('/tpl_categories_next_previous.php',DIR_WS_TEMPLATE, $current_page_base,'templates'). '/tpl_categories_next_previous.php'); ?>
<!--eof tame_cat prev next -->[/php]so you end up with
<!--bof tame_cat prev next -->
<?php require($template->get_template_dir('/tpl_categories_next_previous.php',DIR_WS_TEMPLATE, $current_page_base,'templates'). '/tpl_categories_next_previous.php'); ?>
<!--eof tame_cat prev next -->
<?php
/**
* require the code for listing products
*/
require($template->get_template_dir('tpl_modules_product_listing.php', DIR_WS_TEMPLATE, $current_page_base,'templates'). '/' . 'tpl_modules_product_listing.php');
?>
[/php]You should then see the navigation facility appear on your product listing page.
I get the following error message.
I think the code in tpl_categories_next_previous.php is not entirely correct
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /var/www/vhosts/atisco-developments.nl/httpdocs/includes/templates/template_default/templates/tpl_categories_next_previous.php on line 17
Error finding category
Sorry, I should have mentioned that you will need to change the 3 mysql queries in the code to match your database. So in line 15:
[php]$query = "SELECT * FROM my_database.zen_categories where parent_ID=$tame_parent_cat and categories_status = 1 and categories_id=$tame_this_cat order by sort_order";[/php]you change my_database to the name of your MySQL database. This might resolve the error you had. There are queries on lines 8,15 and 20 where you will need to replace every incidence of my_database with the name of your MySQL database.
Let me know if the problem persists beyond this. If it does it would be very helpful to know what you get if you insert this line after line 15:
[php]exit("$query");[/php]Obviously that would be something you would only do briefly - record the result and then delete the inserted line again.
Moderation
Destination thread ID and reason are required when shown.
Report Post
Tell staff why this post should be reviewed.
Manage cookie preferences
Our cookie policy has been updated, so we need you to review your preferences and consent again.