Zen Cart Logo
Forums / Templates, Stylesheets, Page Layout / Parent Categories Separated In 3 sideboxes

Parent Categories Separated In 3 sideboxes

Locked

Views: 18,913

Results 1 to 20 of 70
This thread is locked. New replies are disabled.
5 Apr 2007, 4:59 PM
#1
enchantedlingerie avatar

enchantedlingerie

Zen Follower

Join Date:
Nov 2005
Posts:
101
Plugin Contributions:
0

Parent Categories Separated In 3 sideboxes

hi everyone im hoping this can be done and easily. i have been searching for a while but have come up with nothing. i found one older post about this but there were no answers so i figured i would give it a shot. i would like to have three category sideboxes one for adults, children and teens. and in each of these side boxes i would like to have the appropriate categories.

is this possible?

thanks for looking

5 Apr 2007, 5:22 PM
#2
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: Parent Categories Separated In 3 sideboxes

Easy is a nebulous term??? You would need to clone/duplicate the /includes/modules/sideboxes/categories.php and the associated /includes/templates/template_default/sideboxes/tpl_categories.php files along with the names files etc and edit these to only display the category that you want and be titled as you want.

This should all be accomplished using the override system to preserve your hard work.

5 Apr 2007, 5:32 PM
#3
enchantedlingerie avatar

enchantedlingerie

Zen Follower

Join Date:
Nov 2005
Posts:
101
Plugin Contributions:
0

Re: Parent Categories Separated In 3 sideboxes

perfect, thanks so much i should be able to do thatL i have cloned other files so it should not be to hard. appreciate the reply

5 Apr 2007, 5:49 PM
#4
enchantedlingerie avatar

enchantedlingerie

Zen Follower

Join Date:
Nov 2005
Posts:
101
Plugin Contributions:
0

Re: Parent Categories Separated In 3 sideboxes

sorry one more question ..... i duplicated the sideboxes just fine but how do i specify which category to show in which sidebox?

5 Apr 2007, 6:49 PM
#5
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: Parent Categories Separated In 3 sideboxes

Duping the boxes is the easy part - defining what needs to be in the box on a dynamic basis becomes a bit more complicated and I have not done this as you are trying to but...

/includes/functions/functions_categories.php I believe is what populates this box
but it mat be the tpl that grabs this and can be adjusted most simply

5 Apr 2007, 10:22 PM
#6
enchantedlingerie avatar

enchantedlingerie

Zen Follower

Join Date:
Nov 2005
Posts:
101
Plugin Contributions:
0

Re: Parent Categories Separated In 3 sideboxes

thanks alot i will give it a go, im sure i will figure it out
i appreciate the help

cara

5 Apr 2007, 11:04 PM
#7
enchantedlingerie avatar

enchantedlingerie

Zen Follower

Join Date:
Nov 2005
Posts:
101
Plugin Contributions:
0

Re: Parent Categories Separated In 3 sideboxes

ok so i think i got myself into more then i can handleL.
i though this would be easier, but i think im going to have to do to much coding to figure this out and im just not good enough with php to do that. im going to look at this a little more but from what i saw in functions_categories.php it looks pretty hard.

if you or anyone has an advice or thoughts on how to go about this they will be of great help, in the mean time im going to see what i can do.

thanks again

6 Apr 2007, 1:40 AM
#8
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Parent Categories Separated In 3 sideboxes

I did a mod to insert another breakline between some of my categories, checking the category id to put it in the right place. You could do a similar thing, screening the current cat being added against a list and skipping it if it is not on the list. This would require editing the code if you add any categories, but it wouldn't be difficult.

I am away from my regular computer so can't give any more info at the moment, but if you still need help I can post later tonoght. (The file wasn't in /functions, but I can't remember which one it was right now.)

6 Apr 2007, 1:49 PM
#9
enchantedlingerie avatar

enchantedlingerie

Zen Follower

Join Date:
Nov 2005
Posts:
101
Plugin Contributions:
0

Re: Parent Categories Separated In 3 sideboxes

if you have the time i would love some help later, im going to work on it now for a while and see if i can figure anything out. but i would defiantly appreciate some more info if you dont mind.

thanks so much for you help

7 Apr 2007, 1:29 AM
#10
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Parent Categories Separated In 3 sideboxes

In /includes/templates/your_template/sideboxes/tpl_categories.php, the categories display list is built with a for loop starting about line 14:

for ($i=0;$i<sizeof($box_categories_array);$i++) {

There are a lot of if tests inside this to determine characteristics of the display, and a switch which is intended to customize individual category line appearance. This switch code can be used in another if test as I did:

//lay a separator between collections and types - gjh42 20070222
if ($box_categories_array[$i]['path'] == 'cPath=81') {
$content .= '<hr id="catBoxDivider2" />' . "\n";
}

You can use this test immediately after the for loop start (say line 15) with its closing } just before the

}

if (SHOW_CATEGORIES_BOX_SPECIALS == 'true' or...

around line 59. This will evaluate whether or not the category should be displayed before determining how to display it.

For your purpose, I suggest something like this (replacing the cPaths with yours):

  for ($i=0;$i<sizeof($box_categories_array);$i++) {
    /* test for cats to display */
    if ($box_categories_array[$i]['path'] ==('cPath=3' or 'cPath=7' or 'cPath=7_25' or 'cPath=7_26' or 'cPath=12')) {

/* many lines of existing code */

    } /* add this */
 }

if (SHOW_CATEGORIES_BOX_SPECIALS == 'true' or...

If the cPath being evaluated is not in this list, it will not be displayed in this sidebox. For the simplest use, it will be necessary to mention every subcategory cPath as well as top cats.

If you have a lot of subcats this could get cumbersome. In this case it will be possible to evaluate for just the topcat id, but will be more complicated. The way I did it for another purpose won't exactly work here, and I would have to think a while to figure a good way to do it.

Let me know how this works for you.

7 Apr 2007, 3:31 AM
#11
enchantedlingerie avatar

enchantedlingerie

Zen Follower

Join Date:
Nov 2005
Posts:
101
Plugin Contributions:
0

Re: Parent Categories Separated In 3 sideboxes

thank you so much i appreciate all your help. ok i have been playing around with this for a while now and i just keep getting parse errors, maybe im placing the code in the wrong area, im going to attach the tpl_catagories.php file, if you dont mind could you just show me where i should be adding this. im 90% sure i understood what you saidL. but as always getting it to work proves difficult.

here is my original file

<?php
/**
 * Side Box Template
 *
 * @package templateSystem
 * @copyright Copyright 2003-2006 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: tpl_categories.php 4162 2006-08-17 03:55:02Z ajeh $
 */
  $content = "";
  
  $content .= '<div id="' . str_replace('_', '-', $box_id . 'Content') . '" class="sideBoxContent">' . "\n";
  for ($i=0;$i<sizeof($box_categories_array);$i++) {
    switch(true) {
// to make a specific category stand out define a new class in the stylesheet example: A.category-holiday
// uncomment the select below and set the cPath=3 to the cPath= your_categories_id
// many variations of this can be done
//      case ($box_categories_array[$i]['path'] == 'cPath=3'):
//        $new_style = 'category-holiday';
//        break;
      case ($box_categories_array[$i]['top'] == 'true'):
        $new_style = 'category-top';
        break;
      case ($box_categories_array[$i]['has_sub_cat']):
        $new_style = 'category-subs';
        break;
      default:
        $new_style = 'category-products';
      }
     if (zen_get_product_types_to_category($box_categories_array[$i]['path']) == 3 or ($box_categories_array[$i]['top'] != 'true' and SHOW_CATEGORIES_SUBCATEGORIES_ALWAYS != 1)) {
        // skip if this is for the document box (==3)
      } else {
      $content .= '<a class="' . $new_style . '" href="' . zen_href_link(FILENAME_DEFAULT, $box_categories_array[$i]['path']) . '">';

      if ($box_categories_array[$i]['current']) {
        if ($box_categories_array[$i]['has_sub_cat']) {
          $content .= '<span class="category-subs-parent">' . $box_categories_array[$i]['name'] . '</span>';
        } else {
          $content .= '<span class="category-subs-selected">' . $box_categories_array[$i]['name'] . '</span>';
        }
      } else {
        $content .= $box_categories_array[$i]['name'];
      }

      if ($box_categories_array[$i]['has_sub_cat']) {
        $content .= CATEGORIES_SEPARATOR;
      }
      $content .= '</a>';

      if (SHOW_COUNTS == 'true') {
        if ((CATEGORIES_COUNT_ZERO == '1' and $box_categories_array[$i]['count'] == 0) or $box_categories_array[$i]['count'] >= 1) {
          $content .= CATEGORIES_COUNT_PREFIX . $box_categories_array[$i]['count'] . CATEGORIES_COUNT_SUFFIX;
        }
      }

      $content .= '<br />' . "\n";
    }
  }

  if (SHOW_CATEGORIES_BOX_SPECIALS == 'true' or SHOW_CATEGORIES_BOX_PRODUCTS_NEW == 'true' or SHOW_CATEGORIES_BOX_FEATURED_PRODUCTS == 'true' or SHOW_CATEGORIES_BOX_PRODUCTS_ALL == 'true') {
// display a separator between categories and links
    if (SHOW_CATEGORIES_SEPARATOR_LINK == '1') {
      $content .= '<hr id="catBoxDivider" />' . "\n";
    }
    if (SHOW_CATEGORIES_BOX_SPECIALS == 'true') {
      $show_this = $db->Execute("select s.products_id from " . TABLE_SPECIALS . " s where s.status= 1 limit 1");
      if ($show_this->RecordCount() > 0) {
        $content .= '<a class="category-links" href="' . zen_href_link(FILENAME_SPECIALS) . '">' . CATEGORIES_BOX_HEADING_SPECIALS . '</a>' . '<br />' . "\n";
      }
    }
    if (SHOW_CATEGORIES_BOX_PRODUCTS_NEW == 'true') {
      // display limits
//      $display_limit = zen_get_products_new_timelimit();
      $display_limit = zen_get_new_date_range();

      $show_this = $db->Execute("select p.products_id
                                 from " . TABLE_PRODUCTS . " p
                                 where p.products_status = 1 " . $display_limit . " limit 1");
      if ($show_this->RecordCount() > 0) {
        $content .= '<a class="category-links" href="' . zen_href_link(FILENAME_PRODUCTS_NEW) . '">' . CATEGORIES_BOX_HEADING_WHATS_NEW . '</a>' . '<br />' . "\n";
      }
    }
    if (SHOW_CATEGORIES_BOX_FEATURED_PRODUCTS == 'true') {
      $show_this = $db->Execute("select products_id from " . TABLE_FEATURED . " where status= 1 limit 1");
      if ($show_this->RecordCount() > 0) {
        $content .= '<a class="category-links" href="' . zen_href_link(FILENAME_FEATURED_PRODUCTS) . '">' . CATEGORIES_BOX_HEADING_FEATURED_PRODUCTS . '</a>' . '<br />' . "\n";
      }
    }
    if (SHOW_CATEGORIES_BOX_PRODUCTS_ALL == 'true') {
      $content .= '<a class="category-links" href="' . zen_href_link(FILENAME_PRODUCTS_ALL) . '">' . CATEGORIES_BOX_HEADING_PRODUCTS_ALL . '</a>' . "\n";
    }
  }
  $content .= '</div>';
?>

thanks so so much i appreciate your help so much

7 Apr 2007, 5:07 AM
#12
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Parent Categories Separated In 3 sideboxes

Try this and see if it works. It is the default file with the display test code added.
You will need to edit cPaths to match your store's.

<?php
/**
 * Side Box Template
 *
 * @package templateSystem
 * @copyright Copyright 2003-2006 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: tpl_categories.php 4162 2006-08-17 03:55:02Z ajeh $
 */
  $content = "";
  
  $content .= '<div id="' . str_replace('_', '-', $box_id . 'Content') . '" class="sideBoxContent">' . "\n";
  for ($i=0;$i<sizeof($box_categories_array);$i++) {
    /* test for cats to display */
    if ($box_categories_array[$i]['path'] == ('cPath=3' or 'cPath=7' or 'cPath=7_25' or 'cPath=7_26' or 'cPath=12')) {

    switch(true) {
// to make a specific category stand out define a new class in the stylesheet example: A.category-holiday
// uncomment the select below and set the cPath=3 to the cPath= your_categories_id
// many variations of this can be done
//      case ($box_categories_array[$i]['path'] == 'cPath=3'):
//        $new_style = 'category-holiday';
//        break;
      case ($box_categories_array[$i]['top'] == 'true'):
        $new_style = 'category-top';
        break;
      case ($box_categories_array[$i]['has_sub_cat']):
        $new_style = 'category-subs';
        break;
      default:
        $new_style = 'category-products';
      }
     if (zen_get_product_types_to_category($box_categories_array[$i]['path']) == 3 or ($box_categories_array[$i]['top'] != 'true' and SHOW_CATEGORIES_SUBCATEGORIES_ALWAYS != 1)) {
        // skip if this is for the document box (==3)
      } else {
      $content .= '<a class="' . $new_style . '" href="' . zen_href_link(FILENAME_DEFAULT, $box_categories_array[$i]['path']) . '">';

      if ($box_categories_array[$i]['current']) {
        if ($box_categories_array[$i]['has_sub_cat']) {
          $content .= '<span class="category-subs-parent">' . $box_categories_array[$i]['name'] . '</span>';
        } else {
          $content .= '<span class="category-subs-selected">' . $box_categories_array[$i]['name'] . '</span>';
        }
      } else {
        $content .= $box_categories_array[$i]['name'];
      }

      if ($box_categories_array[$i]['has_sub_cat']) {
        $content .= CATEGORIES_SEPARATOR;
      }
      $content .= '</a>';

      if (SHOW_COUNTS == 'true') {
        if ((CATEGORIES_COUNT_ZERO == '1' and $box_categories_array[$i]['count'] == 0) or $box_categories_array[$i]['count'] >= 1) {
          $content .= CATEGORIES_COUNT_PREFIX . $box_categories_array[$i]['count'] . CATEGORIES_COUNT_SUFFIX;
        }
      }

      $content .= '<br />' . "\n";
    }
    } /* end cat display test */
  }

  if (SHOW_CATEGORIES_BOX_SPECIALS == 'true' or SHOW_CATEGORIES_BOX_PRODUCTS_NEW == 'true' or SHOW_CATEGORIES_BOX_FEATURED_PRODUCTS == 'true' or SHOW_CATEGORIES_BOX_PRODUCTS_ALL == 'true') {
// display a separator between categories and links
    if (SHOW_CATEGORIES_SEPARATOR_LINK == '1') {
      $content .= '<hr id="catBoxDivider" />' . "\n";
    }
    if (SHOW_CATEGORIES_BOX_SPECIALS == 'true') {
      $show_this = $db->Execute("select s.products_id from " . TABLE_SPECIALS . " s where s.status= 1 limit 1");
      if ($show_this->RecordCount() > 0) {
        $content .= '<a class="category-links" href="' . zen_href_link(FILENAME_SPECIALS) . '">' . CATEGORIES_BOX_HEADING_SPECIALS . '</a>' . '<br />' . "\n";
      }
    }
    if (SHOW_CATEGORIES_BOX_PRODUCTS_NEW == 'true') {
      // display limits
//      $display_limit = zen_get_products_new_timelimit();
      $display_limit = zen_get_new_date_range();

      $show_this = $db->Execute("select p.products_id
                                 from " . TABLE_PRODUCTS . " p
                                 where p.products_status = 1 " . $display_limit . " limit 1");
      if ($show_this->RecordCount() > 0) {
        $content .= '<a class="category-links" href="' . zen_href_link(FILENAME_PRODUCTS_NEW) . '">' . CATEGORIES_BOX_HEADING_WHATS_NEW . '</a>' . '<br />' . "\n";
      }
    }
    if (SHOW_CATEGORIES_BOX_FEATURED_PRODUCTS == 'true') {
      $show_this = $db->Execute("select products_id from " . TABLE_FEATURED . " where status= 1 limit 1");
      if ($show_this->RecordCount() > 0) {
        $content .= '<a class="category-links" href="' . zen_href_link(FILENAME_FEATURED_PRODUCTS) . '">' . CATEGORIES_BOX_HEADING_FEATURED_PRODUCTS . '</a>' . '<br />' . "\n";
      }
    }
    if (SHOW_CATEGORIES_BOX_PRODUCTS_ALL == 'true') {
      $content .= '<a class="category-links" href="' . zen_href_link(FILENAME_PRODUCTS_ALL) . '">' . CATEGORIES_BOX_HEADING_PRODUCTS_ALL . '</a>' . "\n";
    }
  }
  $content .= '</div>';
?>
7 Apr 2007, 5:15 AM
#13
webomat avatar

webomat

Zen Follower

Join Date:
Jan 2005
Location:
Minneapolis MN, USA
Posts:
128
Plugin Contributions:
0

Re: Parent Categories Separated In 3 sideboxes

Hi,

I'm coming late to this discussion, but there's a pretty simple way to my mind... something similar to what I've done with a site that had special needs re displaying the categories. Simply modify a function/query in the \includes\classes\category_tree.php to select based on the top level category.

Here's an overview....

  1. Set up an Adult Category that contains all the categories of adult clothing; set up one for Teens and one for Children.

  2. Write down the Category ID # for each of them.

  3. In \includes\classes\category_tree.php you need to duplicate the entire "function zen_category_tree" section, renaming the function... for instance, "function zen_adult_tree".

  4. Find this section and add the text in red, replacing the # with your number from Step 2 above:

    if ($product_type == 'all') { // added c.categories_id specific here bpeters
      $categories_query = "select c.categories_id, cd.categories_name, c.parent_id, c.categories_image
                             from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd
                             where c.parent_id = 0
                             [B]and c.categories_id = #[/B]
                             and c.categories_id = cd.categories_id
                             and cd.language_id='" . (int)$_SESSION['languages_id'] . "'
                             and c.categories_status= 1
                             order by sort_order, cd.categories_name";
    } else
  1. Duplicate the Categories Sidebox, title it Adult or whatever... change the function call to call the newly defined "tree" in \includes\modules\sideboxes[your template]\categories.php as shown in red text:
// don't build a tree when no categories
    $check_categories = $db->Execute("select categories_id from " . TABLE_CATEGORIES . " where categories_status=1 limit 1");
    if ($check_categories->RecordCount() > 0) {
      $box_categories_array = $main_category_tree->[B]zen_adult_tree();[/B]
    }

Of course changing adult to whatever you need for each box.

  1. I don't know if you'll need to change anything if you're using the Site Map contrib or not, so you might want to check if that applies to your site.

  2. Be aware that the categories may not be expanded in the sidebox to display the subcategories all the time, and the boxes would have one link to "Adult Clothing" and not show anything else until you click on the category link itself. I can't remember what the upshot of this was, because I made additional changes beyond this for that site to meet their specific needs. But that sticks in my mind for some reason.

** Be advised that the mod to the class file will be overwritten during an upgrade, so be sure to save a copy of that file elsewhere -- there is no override in that section. And modifying core code is not always best, but this works and is easy. "-)

I got this from digging around in the forum, found an old post by Ajeh I think that mentioned this method of doing something similar. Anyway, just an idea in case you don't get the other thing working.

Just my two cents!

Cheers,

Becky

7 Apr 2007, 6:05 PM
#14
enchantedlingerie avatar

enchantedlingerie

Zen Follower

Join Date:
Nov 2005
Posts:
101
Plugin Contributions:
0

Re: Parent Categories Separated In 3 sideboxes

ok so im playing with both of these to see which i can get working and which works best.

Webomat thanks so much for the help, i have one question though. im not to experienced with php i have learned alot and learning more every day i assume i know when the function ends but i keep getting errors. so this leads me to think i have no clueL
here is a small part of the code i just want to make sure im doing it right

is the area in red the function i need to duplicate? or am i totally off.
could you tell me exactly what starts and ends this function also where do i place it after copying it? right after the original function i assume.
i understand the rest of how to do this im just confused about where the function starts and ends.

class category_tree extends base {
  function zen_category_tree($product_type = "all")   {
   global $db, $cPath, $cPath_array;
   if ($product_type != 'all') {   
      $sql = "select type_master_type from " . TABLE_PRODUCT_TYPES . "
                where type_master_type = " . $product_type . "";
      $master_type_result = $db->Execute($sql);
      $master_type = $master_type_result->fields['type_master_type'];
 
    }    
 
    $this->tree = array();
    if ($product_type == 'all') {
      $categories_query = "select c.categories_id, cd.categories_name, c.parent_id, c.categories_image
                             from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd
                             where c.parent_id = 0  
                             and c.categories_id = cd.categories_id
                             and cd.language_id='" . (int)$_SESSION['languages_id'] . "'
                             and c.categories_status= 1
                             order by sort_order, cd.categories_name";
    } else {
      $categories_query = "select ptc.category_id as categories_id, cd.categories_name, c.parent_id, c.categories_image
                             from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd, " . TABLE_PRODUCT_TYPES_TO_CATEGORY . " ptc
                             where c.parent_id = 0  
                             and ptc.category_id = cd.categories_id
                             and ptc.product_type_id = " . $master_type . "
                             and c.categories_id = ptc.category_id
                             and cd.language_id=" . (int)$_SESSION['languages_id'] ."
                             and c.categories_status= 1
                             order by sort_order, cd.categories_name";
    }

thanks so much for your help

7 Apr 2007, 8:20 PM
#15
enchantedlingerie avatar

enchantedlingerie

Zen Follower

Join Date:
Nov 2005
Posts:
101
Plugin Contributions:
0

Re: Parent Categories Separated In 3 sideboxes

gjh42 ,

i think your way is going to work best. but im still having problems. let me explain further maybe i left something out. i have cloned the categories sidebox three times i now have categories,categories2,categories3 and categories4 these are how i named the files. so i copied the code you gave me and put it in the tpl_categoreis2.php file as this is the sidebox im trying to change now in tpl_categories2.php there are a number of file names like this $box_categories_array should i add a 2 to the end of categories to match the file name or should i leave it as $box_categories_array
when i change the $box_categories_array to $box_categories2_array it empties the categories out of the sidebox

after copying what you gave me it did not do anything.
when you say c-path you mean the categoryid right?

i really appreciate your help, i hope i have explained myself OK.

7 Apr 2007, 9:02 PM
#16
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Parent Categories Separated In 3 sideboxes

I don't know about the $box_categories_array part of the code... but my inclination would be to leave that as is. If you change it, you may need to carry changes far & wide.

The test code needs to say ('cPath=3' or 'cPath=7' or 'cPath=7_25' or ...) exactly, only replacing the numbers with yours. Of course you can add as many cPath items to the list as you want.
You can get the correct cPaths by navigating to the cat or sub in your store and looking at the address bar.

Note: You may want to try the modified code in the original tpl_categories.php first, to see how it works in something that you know is ok otherwise. One step at a time...

7 Apr 2007, 9:05 PM
#17
enchantedlingerie avatar

enchantedlingerie

Zen Follower

Join Date:
Nov 2005
Posts:
101
Plugin Contributions:
0

Re: Parent Categories Separated In 3 sideboxes

hmmm yeah that's exactly what i did but nothing is showing up.
i though i did it right, you explained it well. i don't get why it wont work.

i though this would be easierL, i should have know better

i appreciate all your help

8 Apr 2007, 2:41 AM
#18
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Parent Categories Separated In 3 sideboxes

Something just occurred to me: the if test may not actually function properly as written. It is intuitively reasonable, but it might be that the comparison logic works differently. I haven't found a solid answer to this yet... will keep looking.

Meanwhile, limiting the test to one 'cPath=3' will avoid this possible problem. If that works, we can reformulate the test statement.

  if (($box_categories_array[$i]['path'] == 'cPath=3') or ($box_categories_array[$i]['path'] == 'cPath=7') or ($box_categories_array[$i]['path'] == 'cPath=7_25')) {

will definitely work, but is unbelievably cumbersome for a long list. There will be a more elegant way of stating it.

I suppose the first space-saver would be to substitute a simple variable for the $box expression.```php
$cPTest = $box_categories_array[$i]['path'];
if (($cPTest == 'cPath=3') or ($cPTest == 'cPath=7') or($cPTest == 'cPath=7_25')) }


Hope this will do it.
8 Apr 2007, 5:26 PM
#19
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Parent Categories Separated In 3 sideboxes

A little research gave me this (turn the cPath list into an array, then see if $box matches any array item):

 if(in_array($box_categories_array[$i]['path'], explode(",",'cPath=3','cPath=7','cPath=7_25'))) {

After I came up with this, I realized it is the same method used in tpl_main_page.php to turn off sideboxes on specified pages.

If the cat list is long, a further condensation is possible:

$cPTest = str_replace("=","",strchr($box_categories_array[$i]['path'],"="));
if(in_array($cPTest, explode(",",'3','7','7_25'))) {

Strchr will return the $box value from = to the end, and str_replace will strip the =, giving a smaller string to test for.

9 Apr 2007, 3:21 PM
#20
enchantedlingerie avatar

enchantedlingerie

Zen Follower

Join Date:
Nov 2005
Posts:
101
Plugin Contributions:
0

Re: Parent Categories Separated In 3 sideboxes

ok i think we are getting close. i tried using the code from post 19 but i kept getting parse errors. i tired the codes from post 18 this one seemed to work

if (($box_categories_array[$i]['path'] == 'cPath=42') or ($box_categories_array[$i]['path'] == 'cPath=51') or ($box_categories_array[$i]['path'] == 'cPath=70')) {  
 

but it would only show two categories it would not show the third and if i added more to the array it would not show those either.

i also tried this code

$cPTest = $box_categories_array[$i]['path'];
   if (($cPTest == 'cPath=3') or ($cPTest == 'cPath=7') or($cPTest == 'cPath=7_25')) }  

but it gave me this error

[B]Parse error[/B]: syntax error, unexpected '}' in [B]/home/cara1977/public_html/gothenaturalway/includes/templates/classic/sideboxes/tpl_categories.php[/B] on line [B]15[/B]
 

i know i keep saying it but i appreciate your help so much, im going to keep playing with this a little bit code 1 above seem to work best so far i just need to get it to show more then two categories.

thanks a ton:smile: