Page 1 of 2 12 LastLast
Results 1 to 10 of 16
  1. #1
    Join Date
    Sep 2009
    Posts
    78
    Plugin Contributions
    0

    help question $box_categories_array[i]['sort_order'] ?

    In tpl_categories.php, I am able to extract the cPath of each category through $box_categories_array[$i]['path'].

    I am not sure, however, whether there is $box_categories_array[$i]['sort_order'] as I actually need to extract the sort order of each category and not the cPath.

    Where can I find more information about the $box_categories_array[$i] array?

    If there isn't additional information source, do you happen to know the name of the variable that returns the sort order for a given category?

    Thanks.

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

    Default Re: $box_categories_array[i]['sort_order'] ?

    /includes/classes/category_tree.php

    The categories are retrieved and ordered by sort order and name, but the numerical sort order that was originally assigned to the categories is not brought out. This will be 0 for all categories unless one has been specifically assigned, so the order in $box_categories_array[$i] given by $i is as useful as anything.

  3. #3
    Join Date
    Sep 2009
    Posts
    78
    Plugin Contributions
    0

    help question Re: $box_categories_array[i]['sort_order'] ?

    Quote Originally Posted by gjh42 View Post
    but the numerical sort order that was originally assigned to the categories is not brought out. This will be 0 for all categories
    Aha! That explains something I observed yesterday but didn't understand: I initially tried to use $i but it always had the value of 0. If $i is indeed the sort order (as entered in the Admin console), this could explain why it was always 0, because as the Admin, I left all categories with the default sort order value of 0.

    However, that doesn't explain why the loop in tpl_categories.php works:
    PHP Code:
      for ($i=0;$i<sizeof($box_categories_array);$i++) { 
    if $i is always 0, how come all categories are listed and processed properly?

    Clearly I am missing something.


    Quote Originally Posted by gjh42 View Post
    unless one has been specifically assigned,
    Assuming all sort orders have been specifically assigned (and are different from the default 0), how do I retrieve them?

    So far, I have been able to find only the following indicies for box_categories_array: top, path, current, name, image, has_sub_cat and count -- but no 'sort_order'.

    Quote Originally Posted by gjh42 View Post
    so the order in $box_categories_array[$i] given by $i is as useful as anything.
    That would have been good enough for me, except that $i is stuck at 0, despite having at least 6 categories. I may have hit a mental block (happens to me when I look at the same code for too many hours).

    Thanks.

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

    Default Re: $box_categories_array[i]['sort_order'] ?

    $i doesn't have any meaningful value outside the loop where it is used. It is not "stuck at 0", but unassigned. We need to know more about what you want to do with the sort orders before giving any advice.

  5. #5
    Join Date
    Sep 2009
    Posts
    78
    Plugin Contributions
    0

    help question Re: $box_categories_array[i]['sort_order'] ?

    Quote Originally Posted by gjh42 View Post
    We need to know more about what you want to do with the sort orders before giving any advice.
    I want to assign a modulus 4 value to a new variable I create. e.g. if my new variable is $my_var:
    PHP Code:
    $my_var $sort_order 4

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

    Default Re: $box_categories_array[i]['sort_order'] ?

    $my_var is going to have to be used and done with before the end of each iteration of the loop... unless you make it an array to store the current value. Inside the loop $i is going to be the most direct method of accessing sort order.
    Knowing something about what you want to accomplish with this is what will let us advise on a practical approach.

  7. #7
    Join Date
    Sep 2009
    Posts
    78
    Plugin Contributions
    0

    help question Re: $box_categories_array[i]['sort_order'] ?

    Quote Originally Posted by gjh42 View Post
    $my_var is going to have to be used and done with before the end of each iteration of the loop.
    Indeed this is how I intend to use it.

    Quote Originally Posted by gjh42 View Post
    Inside the loop $i is going to be the most direct method of accessing sort order.
    Do you mean $i is actually $sort_order?


    Quote Originally Posted by gjh42 View Post
    Knowing something about what you want to accomplish with this is what will let us advise on a practical approach.
    PHP Code:
       switch($sort_order) {
          case 
    0:
             
    $css_cat_id 'style_one';
          break;
          case 
    1:
             
    $css_cat_id 'style_two';
          break;
          case 
    2:
             
    $css_cat_id 'style_three';
          break;
          case 
    3:
             
    $css_cat_id 'style_four';
          break;
       } 
    In other words, I am trying to give a repeating style id every 4th category (currently there is only a style class, identical to all categories).

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

    Default Re: $box_categories_array[i]['sort_order'] ?

    It is possible for $i to skip values in the output, so a strict mod 4 needs its own counter within the output section.

    If the styles repeat, you don't want to use ids; they must be unique. But four repeating/rotating style classes are perfectly valid, as are multiple classes for an element.
    There is a much simpler way of doing the repeat: using a mod 4 operation on the counter, then assigning the result as the suffix of the classname. $new_style already holds the classname, and it can hold two of them just as well.
    PHP Code:
    $modcount 0//initialize above loop

    $new_style .= ' repeat_' int(($modcount 4) *4); // % is modulus operator
    $modcount ++; //increment 
    This can go in tpl_categories.php below the if/else:
    PHP Code:
      $content "";
      
    $modcount 0//initialize above loop

      
    $content .= '<div id="' str_replace('_''-'$box_id 'Content') . '" class="sideBoxContent">' "\n";
      for (
    $i=0;$i<sizeof($box_categories_array);$i++) {
        switch(
    true) {
    //...
          
    default:
            
    $new_style 'category-products';
          }
         if (
    zen_get_product_types_to_category($box_categories_array[$i]['path']) == or ($box_categories_array[$i]['top'] != 'true' and SHOW_CATEGORIES_SUBCATEGORIES_ALWAYS != 1)) {
            
    // skip if this is for the document box (==3)
          
    } else {
          
    $new_style .= ' repeat_' int(($modcount 4) *4); // % is modulus operator
          
    $modcount ++; //increment
          
    $content .= '<a class="' $new_style '" href="' zen_href_link(FILENAME_DEFAULT$box_categories_array[$i]['path']) . '">'
    This will make $new_style equal to 'category-top repeat_0' or whatever the particular values are.
    Last edited by gjh42; 24 Aug 2010 at 03:01 PM.

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

    Default Re: $box_categories_array[i]['sort_order'] ?

    Pardon me, I was looking at the
    switch($sort_order) {
    in your previous post and forgetting that you already had the mod operation covered.

  10. #10
    Join Date
    Sep 2009
    Posts
    78
    Plugin Contributions
    0

    help question Re: $box_categories_array[i]['sort_order'] ?

    Quote Originally Posted by gjh42 View Post
    If the styles repeat, you don't want to use ids; they must be unique.
    Oops... you are absolutely correct. What an embarrassing oversight. I wonder why the w3.org CSS validator didn't catch this.

    Anyway, I do have a working solution based on 'path', but I am really interested in 'sort_order' since this is a number I can control via the Admin console, indirectly controlling the style (image or color) of the category.

    Is 'sort_order" un-retrievable?

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 1
    Last Post: 29 Aug 2013, 05:57 AM
  2. sort_order in Configuration table insert
    By torvista in forum Built-in Shipping and Payment Modules
    Replies: 5
    Last Post: 18 Oct 2008, 07:54 PM
  3. need help finding a core function $box_categories_Array
    By alienfactory in forum Templates, Stylesheets, Page Layout
    Replies: 2
    Last Post: 9 Jul 2008, 05:08 PM

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