Results 1 to 9 of 9
  1. #1
    Join Date
    May 2007
    Posts
    6
    Plugin Contributions
    0

    help question Browsing Categories

    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??

    Many thanks for any help.

  2. #2
    Join Date
    Jul 2005
    Location
    Upstate NY
    Posts
    22,010
    Plugin Contributions
    25

    Default Re: Browsing Categories

    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.

  3. #3
    Join Date
    May 2007
    Posts
    6
    Plugin Contributions
    0

    Default Re: Browsing Categories

    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 may also consider coding it.

    Thanks again.

  4. #4
    Join Date
    May 2007
    Posts
    6
    Plugin Contributions
    0

    Default Re: Browsing Categories

    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 Code:
    <?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">

    <? if($tame_prev) {
        ?><div class="navNextPrevList"><a href="index.php?main_page=index&amp;cPath=<? echo $tame_top_cat."_".$tame_prev; ?>"><span class="cssButton button_prev" onmouseover="this.className='cssButtonHover button_prev button_prevHover'" onmouseout="this.className='cssButton button_prev'" style="width: 80px;">&nbsp;Previous&nbsp;</span></a></div><?
    }?>

    <div class="navNextPrevList"><a href="index.php?main_page=index&amp;cPath=<? echo $tame_top_cat; ?>"><span class="cssButton button_prev" onmouseover="this.className='cssButtonHover button_prev button_prevHover'" onmouseout="this.className='cssButton button_prev'" >Spring Summer 2007 Catalogue</span></a></div>
    <?
    if($tame_next) {
        ?><div class="navNextPrevList"><a href="index.php?main_page=index&amp;cPath=<? echo $tame_top_cat."_".$tame_next; ?>"><span class="cssButton button_next" onmouseover="this.className='cssButtonHover button_next button_nextHover'" onmouseout="this.className='cssButton button_next'" style="width: 80px;">&nbsp;Next&nbsp;</span></a></div><?
    }
    ?>
    </div>

  5. #5
    Join Date
    May 2007
    Posts
    6
    Plugin Contributions
    0

    Default Re: Browsing Categories

    Just added some improved error handling and other bits which make it work better...

    PHP Code:
    <?php
    ## my plugin : does next /previous for categories
    ## current category / top cat
    $tame_cats explode("_",$_GET['cPath']);
    $tame_parent_cat $tame_cats[0];
    $tame_this_cat $tame_cats[1];
    ## check parent cat exists and get name:
    $query "select zen_categories_description.categories_name from my_database.zen_categories_description,my_database.zen_categories where zen_categories_description.categories_id = relaxshoe.zen_categories.categories_id and relaxshoe.zen_categories.categories_status = 1 AND zen_categories.categories_id = $tame_parent_cat";
    $result mysql_query($query);
    $tame_numrows mysql_num_rows($result);
    if(!(
    $tame_numrows && !mysql_error())) exit ("Error finding category");
    $row mysql_fetch_array($result,MYSQL_ASSOC);
    $tame_parent_cat_name $row['categories_name'];
    ## check child cat exits
    $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";
    $result mysql_query($query);
    $tame_numrows mysql_num_rows($result);
    if(!(
    $tame_numrows && !mysql_error())) exit ("Error finding category");
    ## get active ranges for this parent cat...
    $query "SELECT * FROM my_database.zen_categories where parent_ID=$tame_parent_cat and categories_status = 1 order by sort_order";
    $result mysql_query($query);
    $tame_numrows mysql_num_rows($result);
    $i 0;
    if(!(
    $tame_numrows && !mysql_error())) exit ("Error finding category");
    ## now we can go ahead:
    $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"><?
    if($tame_prev) {
        ?><div class="navNextPrevList"><a href="index.php?main_page=index&amp;cPath=<? echo $tame_parent_cat."_".$tame_prev; ?>"><span class="cssButton button_prev" onmouseover="this.className='cssButtonHover button_prev button_prevHover'" onmouseout="this.className='cssButton button_prev'" style="width: 80px;">&nbsp;Previous&nbsp;</span></a></div><?
    }
    ?><div class="navNextPrevList"><a href="index.php?main_page=index&amp;cPath=<? echo $tame_parent_cat; ?>"><span class="cssButton button_prev" onmouseover="this.className='cssButtonHover button_prev button_prevHover'" onmouseout="this.className='cssButton button_prev'" ><? echo $tame_parent_cat_name;?></span></a></div><?
    if($tame_next) {
        ?><div class="navNextPrevList"><a href="index.php?main_page=index&amp;cPath=<? echo $tame_parent_cat."_".$tame_next; ?>"><span class="cssButton button_next" onmouseover="this.className='cssButtonHover button_next button_nextHover'" onmouseout="this.className='cssButton button_next'" style="width: 80px;">&nbsp;Next&nbsp;</span></a></div><?
    }
    ?></div>

  6. #6

    Default Re: Browsing Categories

    Could you please upload this as a plugin?
    I really would like to use it.

    Regards,

    Bram

  7. #7
    Join Date
    May 2007
    Posts
    6
    Plugin Contributions
    0

    Default Re: Browsing Categories

    Hi Bram

    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 Code:
    // draw filter_id (ie: category/mfg depending on $options)
      if ($do_filter_list) {
        echo zen_draw_pull_down_menu('filter_id', $options, (isset($_GET['filter_id']) ? $_GET['filter_id'] : ''), 'onchange="this.form.submit()"');
      }

      // draw alpha sorter
      require(DIR_WS_MODULES . zen_get_module_directory(FILENAME_PRODUCT_LISTING_ALPHA_SORTER));
    ?>
    </form>
    <?php
      
    }
    ?>

    <?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');
    ?>
    You need to insert this code

    PHP Code:
    <!--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 -->
    so you end up with

    PHP Code:
    // draw alpha sorter
      require(DIR_WS_MODULES . zen_get_module_directory(FILENAME_PRODUCT_LISTING_ALPHA_SORTER));
    ?>
    </form>
    <?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
    /**
     * 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');
    ?>
    You should then see the navigation facility appear on your product listing page.

    Let me know how you get on.

  8. #8

    Default Re: Browsing Categories

    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

    Regards,

    Bram

  9. #9
    Join Date
    May 2007
    Posts
    6
    Plugin Contributions
    0

    Default Re: Browsing Categories

    Hi Bram

    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 Code:
    $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"
    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 Code:
    exit("$query"); 
    Obviously that would be something you would only do briefly - record the result and then delete the inserted line again.

 

 

Similar Threads

  1. Replies: 1
    Last Post: 9 May 2011, 05:12 PM
  2. Something is going wrong when browsing through categories
    By goalsurfer in forum General Questions
    Replies: 7
    Last Post: 7 Nov 2010, 06:00 AM
  3. Replies: 3
    Last Post: 13 Jul 2009, 05:23 PM
  4. having trouble when browsing through categories
    By blackinches in forum Setting Up Categories, Products, Attributes
    Replies: 1
    Last Post: 20 Dec 2006, 01:05 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg