Results 1 to 3 of 3

Hybrid View

  1. #1
    Join Date
    May 2014
    Location
    Planet Earth
    Posts
    18
    Plugin Contributions
    0

    Default Re: Display Current Category Image in Custom Menu

    Problem solved.

    In my efforts to understand why the code I had been using failed to render properly, I led myself on a weeks long wild goose chase in my obsession to discover the answer.

    I was so focused on the idea that the code I introduced should have worked, I overlooked the fact that I failed to introduce a new image element to my array AND in the process of trying all manner of variations of the code I thought should work, ignored the existing category name element that I knew did work.

    Here is the solution in the hope I spare some other person looking to do something similar, valuable time. (I am only including the parts of categories_ul_generator.php that needed changes for my solution to work and to give a reference point for those interested.)

    PHP Code:
     global $languages_id$db;
            
    $this->data = array();
      
           
    // I am using * as it fetches all fields.        
            
            
    $categories_query "select * 
                                            from " 
    TABLE_CATEGORIES " c, " TABLE_CATEGORIES_DESCRIPTION " cd
                                            where c.categories_id = cd.categories_id
                                            and c.categories_status=1 " 
    .
                                            
    " and cd.language_id = '" . (int)$_SESSION['languages_id'] . "' " .
                                            
    " order by c.parent_id, c.sort_order, cd.categories_name";
            
    $categories $db->Execute($categories_query);
            while (!
    $categories->EOF) {

    // The following is the ORIGINAL bit of code I needed to change.  Compare it to the next line to see the solution.

    //            $this->data[$categories->fields['parent_id']][$categories->fields['categories_id']] = array('name' => $categories->fields['categories_name'], 'count' => 0);    

    // In order to display each category image, a new element must be included in the array.  In this case the element "image" is introduced.
     
            
    $this->data[$categories->fields['parent_id']][$categories->fields['categories_id']] = array('name' => $categories->fields['categories_name'], 'image' => $categories->fields['categories_image'], 'count' => 0);    
            
    $categories->MoveNext();
            }
        } 
    Now that the element has been added to the array, I can complete my solution by including both the 'name' and 'image' elements in my result.

    PHP Code:
        function buildBranch($parent_id$level$submenu=true$parent_link='')
        {
            
    $result sprintf($this->parent_group_start_string, ($submenu==true) ? ' class="level'. ($level+1) . '"' '' );
                {
                foreach(
    $this->data[$parent_id] as $category_id => $category) {
                    
    $category_link $parent_link $category_id;
                    if ((
    $this->data[$category_id])) {
                        
    $result .= sprintf($this->child_start_string, ($submenu==true) ? ' class="submenu"' '');
                    } else {
                        
    $result .= sprintf($this->child_start_string'');
                    }

    $result .= str_repeat($this->spacer_string$this->spacer_multiplier 1) . '<a href="' zen_href_link(FILENAME_DEFAULT'cPath=' $category_link) . '">' zen_image(DIR_WS_IMAGES $category['image'], $category['name'], SUBCATEGORY_IMAGE_WIDTHSUBCATEGORY_IMAGE_HEIGHT) . '<br />' $category['name'] . '</a>'
    If I had included all this information from the get go, someone may have seen the problem and advised me on a solution when I first posted. My bad, lesson learned.

    All this said, if someone knows the proper code to specify the height and width of each image in the $result I posted, please advise, it would be greatly appreciated.

    I realize I am using SUBCATEGORY_IMAGE_WIDTH and SUBCATEGORY_IMAGE_HEIGHT but I am only using the top category for my menu and I'm not sure this is the correct code. If I am using the correct code, I'd like it clarified.

    Thanks!
    Last edited by Enzo; 29 Jun 2014 at 03:54 PM.

 

 

Similar Threads

  1. Flyout Menu highlight current category
    By scott_ease in forum Templates, Stylesheets, Page Layout
    Replies: 5
    Last Post: 28 Jul 2012, 06:06 PM
  2. How do i display category list in my current tmeplate
    By aspiringDev in forum General Questions
    Replies: 2
    Last Post: 19 Aug 2011, 01:11 PM
  3. Ways to style CURRENT category menu choice?
    By pixelwrangler in forum Templates, Stylesheets, Page Layout
    Replies: 5
    Last Post: 7 Apr 2009, 12:14 AM
  4. Custom Category Navigation Menu
    By antondesignstudio in forum General Questions
    Replies: 2
    Last Post: 23 Sep 2008, 10:13 PM
  5. Can I Display Specials only for current category?
    By paperthreads in forum Setting Up Specials and SaleMaker
    Replies: 4
    Last Post: 12 Apr 2008, 10:30 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