Results 1 to 10 of 10
  1. #1
    Join Date
    Apr 2010
    Posts
    282
    Plugin Contributions
    1

    Default internal link to category number

    I am trying to make my own sub-category drop down menu, and I need to know what code to use for an internal link to a specific category number?

  2. #2
    Join Date
    Dec 2009
    Location
    Amersfoort, The Netherlands
    Posts
    2,845
    Plugin Contributions
    25

    Default Re: internal link to category number

    I do not have the code at hand right now, but i think it is the function zen_get_caregorry_tree(), you can use

  3. #3
    Join Date
    Feb 2012
    Location
    mostly harmless
    Posts
    1,809
    Plugin Contributions
    8

    Default Re: internal link to category number

    One should use the function zen_href_link() to generate URLs for links.

    PHPDocs for zen_href_link:
    Code:
    	/**
    	 * Generates the link to the requested page suitable for use in an href
    	 * paramater.
    	 *
    	 * @param string $page the name of the page
    	 * @param string $parameters any paramaters for the page
    	 * @param string $connection 'NONSSL' or 'SSL' the type of connection to use.
    	 * @param bool $add_session_id true if a session id can be added to the url, false otherwise.
    	 * @param bool $search_engine_safe true if we should use search engine safe urls, false otherwise
    	 * @param bool $static true if this is a static page (no paramaters)
    	 * @param bool $use_dir_ws_catalog true if we should use the DIR_WS_CATALOG / DIR_WS_HTTPS_CATALOG from the configuration
    	 * @return string
    	 */
    	zen_href_link($page = '', $parameters = '', $connection = 'NONSSL', $add_session_id = true, $search_engine_safe = true, $static = false, $use_dir_ws_catalog = true)
    Examples for categories:
    Code:
    # Generate a URL for category 3, use HTTP/HTTPS based on current request ("DVD Movies" in the sample DB)
    zen_href_link(FILENAME_DEFAULT, 'cPath=3', $request_type);
    
    # Generate a URL for category 10 (inside category 3), use HTTP/HTTPS based on current request ("DVD Movies" -> "Action" in the sample DB)
    zen_href_link(FILENAME_DEFAULT, 'cPath=3_10', $request_type);
    
    # Create the HTML element for a link, use HTTP/HTTPS based on current request, use category name for the current users language  ("DVD Movies" -> "Action" in the sample DB)
    <a href="<?php echo zen_href_link(FILENAME_DEFAULT, 'cPath=3_10', $request_type); ?>"><?php echo zen_get_categories_name('10'); ?></a>

    Note 1: One should use the full cPath (category path) when generating URLs to be consistent with the stock Zen Cart code. The example above includes a top level category and child category (of a top level category).

    Note 2: You can look at the code for the stock "categories" sidebox as an example. The controller code is in "/includes/modules/sideboxes/categories.php" and the HTML template is in "/includes/templates/template_default/sideboxes/tpl_categories.php". Do not directly edit these files! To override the controller code, create a folder with the same name as your theme and place a COPY in the new folder. To override the template code, copy the template file to "/includes/templates/your_theme_name/sideboxes/tpl_categories.php".
    Last edited by lhungil; 1 Nov 2015 at 08:29 AM. Reason: Added note about locations of the stock categories sidebox.
    The glass is not half full. The glass is not half empty. The glass is simply too big!
    Where are the Zen Cart Debug Logs? Where are the HTTP 500 / Server Error Logs?
    Zen Cart related projects maintained by lhûngîl : Plugin / Module Tracker

  4. #4
    Join Date
    Feb 2012
    Location
    mostly harmless
    Posts
    1,809
    Plugin Contributions
    8

    Default Re: internal link to category number

    Quote Originally Posted by Design75 View Post
    I do not have the code at hand right now, but i think it is the function zen_get_category_tree(), you can use
    Thank You for bringing this up! The method zen_get_category_tree() is valuable to generate a category tree (placed in an array). Each category in the tree created by this method will also contain information about the category such as the cPath, name, image, etc. This method is available in the "category_tree" class.

    In the template one will still need to use the zen_href_link() function to generate the URL and display other category details. There is also a function zen_image() for adding "img" HTML elements (one can use this to add a category image to the dropdown - although personally I would probably use a small thumbnail based sprite + CSS instead).


    NOTE: Best practice is to use the Zen Cart functions and classes whenever possible for accessing the database or outputting HTML. One may wish to review the files inside the folders "/includes/functions/" and "/includes/classes/" to see what is available. Using the provided functions and classes helps avoids some potential issues and helps to maintain compatibility with other "plugins" and future Zen Cart upgrades.
    The glass is not half full. The glass is not half empty. The glass is simply too big!
    Where are the Zen Cart Debug Logs? Where are the HTTP 500 / Server Error Logs?
    Zen Cart related projects maintained by lhûngîl : Plugin / Module Tracker

  5. #5
    Join Date
    Apr 2010
    Posts
    282
    Plugin Contributions
    1

    Default Re: internal link to category number

    Thank you. I was able to get my drop down menu to work. I copied the information drop down menu in the tableau thread, and modified it.
    header.php
    Code:
    <li>
    <a href="#" class="information-top">
    <span><?php echo zen_get_categories_name('13'); ?></span>
    </a>
    <?php require($template->get_template_dir('tpl_modules_allison_tabs.php',DIR_WS_TEMPLATE, $current_page_base,'templates'). '/tpl_modules_allison_tabs.php'); ?>
    </li>
    tpl_modules_allison_tabs:
    <?php
    if ($nmx_disk_cache->cacheStart('tpl_modules_allison_tabs', array($_SESSION['languages_id']), true, true)) {
    ?>

    <ul class="sub-menu">
    <li class="topmenu no-js"><a href="<?php echo zen_href_link(FILENAME_DEFAULT, 'cPath=13_1', $request_type); ?>" class="category-top"><?php echo zen_get_categories_name('1'); ?></a>
    </li>
    <li class="topmenu no-js"><a href="<?php echo zen_href_link(FILENAME_DEFAULT, 'cPath=13_29', $request_type); ?>" class="category-top"><?php echo zen_get_categories_name('29'); ?></a>
    </li>
    <li class="topmenu no-js"><a href="<?php echo zen_href_link(FILENAME_DEFAULT, 'cPath=13_16', $request_type); ?>" class="category-top"><?php echo zen_get_categories_name('16'); ?></a>
    </li>
    <li class="topmenu no-js"><a href="<?php echo zen_href_link(FILENAME_DEFAULT, 'cPath=13_19', $request_type); ?>" class="category-top"><?php echo zen_get_categories_name('19'); ?></a>
    </li>
    </ul>


    <?php
    $nmx_disk_cache->cacheEnd();
    }
    ?>
    Right now, it is only on my test site, but once I build one for each category, it will be live.
    https://redsautorehab.com/newzen/

    The main reason for doing this, is because the category drop down menu built in to the template does not expand the sub categories on mobile devices, which makes navigation horrible.
    Last edited by vanhorn_s; 1 Nov 2015 at 06:24 PM.

  6. #6
    Join Date
    Jul 2012
    Posts
    16,817
    Plugin Contributions
    17

    Default Re: internal link to category number

    Quote Originally Posted by vanhorn_s View Post
    Thank you. I was able to get my drop down menu to work. I copied the information drop down menu in the tableau thread, and modified it.
    header.php
    Code:
    <li>
    <a href="#" class="information-top">
    <span><?php echo zen_get_categories_name('13'); ?></span>
    </a>
    <?php require($template->get_template_dir('tpl_modules_allison_tabs.php',DIR_WS_TEMPLATE, $current_page_base,'templates'). '/tpl_modules_allison_tabs.php'); ?>
    </li>
    tpl_modules_allison_tabs:

    Right now, it is only on my test site, but once I build one for each category, it will be live.
    https://redsautorehab.com/newzen/

    The main reason for doing this, is because the category drop down menu built in to the template does not expand the sub categories on mobile devices, which makes navigation horrible.
    Umm.. Are you painstakingly manually entering each of the category entries below?

    Code:
     	 		 			 			 				<?php
      if ($nmx_disk_cache->cacheStart('tpl_modules_allison_tabs', array($_SESSION['languages_id']), true, true)) {  
    ?>
    
        <ul class="sub-menu">
    		<li class="topmenu no-js"><a href="<?php echo  zen_href_link(FILENAME_DEFAULT, 'cPath=13_1', $request_type); ?>"  class="category-top"><?php echo zen_get_categories_name('1');  ?></a>
    		</li>
    		<li class="topmenu no-js"><a href="<?php echo  zen_href_link(FILENAME_DEFAULT, 'cPath=13_29', $request_type); ?>"  class="category-top"><?php echo zen_get_categories_name('29');  ?></a>
    		</li>
    		<li class="topmenu no-js"><a href="<?php echo  zen_href_link(FILENAME_DEFAULT, 'cPath=13_16', $request_type); ?>"  class="category-top"><?php echo zen_get_categories_name('16');  ?></a>
    		</li>
    		<li class="topmenu no-js"><a href="<?php echo  zen_href_link(FILENAME_DEFAULT, 'cPath=13_19', $request_type); ?>"  class="category-top"><?php echo zen_get_categories_name('19');  ?></a>
    		</li>		
        </ul>
        
    	
    <?php
      $nmx_disk_cache->cacheEnd();
    }
    ?>



    Let me ask you something, do you see any kind of pattern? Perhaps a way that you could use data in the database to provide the requested information instead of manually updating this? What happens if you either add or remove a category? How much work will need to be done? Is that something you have the time to accomplish instead of doing something else?

    No don't have to go it alone, but would hope that some improvement might make things go quicker and if such an issue is occurring, then perhaps the original code needs to be updated...
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  7. #7
    Join Date
    Apr 2010
    Posts
    282
    Plugin Contributions
    1

    Default Re: internal link to category number

    Quote Originally Posted by mc12345678 View Post
    Umm.. Are you painstakingly manually entering each of the category entries below?

    Code:
     	 		 			 			 				<?php
      if ($nmx_disk_cache->cacheStart('tpl_modules_allison_tabs', array($_SESSION['languages_id']), true, true)) {  
    ?>
    
        <ul class="sub-menu">
    		<li class="topmenu no-js"><a href="<?php echo  zen_href_link(FILENAME_DEFAULT, 'cPath=13_1', $request_type); ?>"  class="category-top"><?php echo zen_get_categories_name('1');  ?></a>
    		</li>
    		<li class="topmenu no-js"><a href="<?php echo  zen_href_link(FILENAME_DEFAULT, 'cPath=13_29', $request_type); ?>"  class="category-top"><?php echo zen_get_categories_name('29');  ?></a>
    		</li>
    		<li class="topmenu no-js"><a href="<?php echo  zen_href_link(FILENAME_DEFAULT, 'cPath=13_16', $request_type); ?>"  class="category-top"><?php echo zen_get_categories_name('16');  ?></a>
    		</li>
    		<li class="topmenu no-js"><a href="<?php echo  zen_href_link(FILENAME_DEFAULT, 'cPath=13_19', $request_type); ?>"  class="category-top"><?php echo zen_get_categories_name('19');  ?></a>
    		</li>		
        </ul>
        
    	
    <?php
      $nmx_disk_cache->cacheEnd();
    }
    ?>



    Let me ask you something, do you see any kind of pattern? Perhaps a way that you could use data in the database to provide the requested information instead of manually updating this? What happens if you either add or remove a category? How much work will need to be done? Is that something you have the time to accomplish instead of doing something else?

    No don't have to go it alone, but would hope that some improvement might make things go quicker and if such an issue is occurring, then perhaps the original code needs to be updated...
    Yes, I did painstakingly add all of the category numbers. I needed a quick solution for this, because I have not had a single order since I went live with the tableau template, and I noticed that navigation is terrible since I went live, because the subcategories did not expand on mobile devices. When I asked about it on the tableau thread, this is the response I got:
    RE: Sub Categories - The Category Menu that comes stock in the Tableau template is a one level menu. That is not a bug. If you want something with multiple sub menus you will need to install a different category menu. My guess is this was done on purpose because when on mobile you don't want to complicate things with submenus (the styling becomes quite tricky to execute.)
    From my first attempt with this template, until now, I have gotten the distinct impression that Numinix takes forever to correct flaws, and if they don't see this as a flaw, it may never get corrected.

    If I change categories around, I will have to look this thread up, so I can see what I did.
    I don't change my site very often though, because I have an automotive repair business to run too.


    I have finished the drop down menu for each category, and have gone live.
    http://www.redsautorehab.com

  8. #8
    Join Date
    Apr 2010
    Posts
    282
    Plugin Contributions
    1

    Default Re: internal link to category number

    I also added to the jquery_jpanel.js file for each menu.
    Code:
    		jQuery('li a.allison-top').on('click', function(){
    		if (jQuery(this).parent().find('.sub-menu').is(':hidden')) {
    			jQuery('#jPanelMenu-menu .hasSub a.allison-top').removeClass('expanded-cat');
    			jQuery(this).parent().children('a.allison-top').addClass('expanded-cat');
    			jQuery('#jPanelMenu-menu #nav-menu ul li ul').hide();
    			jQuery(this).parent().find('.sub-menu').slideDown();
    			return false;
    		} else {
    			return true;
    		}
    	});

  9. #9
    Join Date
    Apr 2010
    Posts
    282
    Plugin Contributions
    1

    Default Re: internal link to category number

    Quote Originally Posted by mc12345678 View Post
    Umm.. Are you painstakingly manually entering each of the category entries below?
    Let me ask you something, do you see any kind of pattern? Perhaps a way that you could use data in the database to provide the requested information instead of manually updating this? What happens if you either add or remove a category? How much work will need to be done? Is that something you have the time to accomplish instead of doing something else?

    No don't have to go it alone, but would hope that some improvement might make things go quicker and if such an issue is occurring, then perhaps the original code needs to be updated...
    I'm not great with php. I'm an automotive mechanic who started his own ecommerce business. I do see a pattern, but I didn't know how else to do this, and I really needed to make the website mobile navigation friendly again. If anybody has any suggestions on how to improve upon this code, and make it work in a way that won't be affected when categories change, I am all ears.

  10. #10
    Join Date
    Jun 2007
    Posts
    474
    Plugin Contributions
    2

    Default Re: internal link to category number

    vanhorn_s, that was me who gave you that response about the template. Just to be clear, I'm not Numinix. Numinix might provide a different answer.

    That being said, there is most likely a way to tie what you have done here into the Drop_Menu Plugin: https://www.zen-cart.com/downloads.php?do=file&id=323

    That plugin will handle the automation side of things. That is the menu tool I am using, but I'm still not going with sub categories.

    I would be very surprised if 'no subcategories for mobile visitors' is the actual cause of total conversion loss on your site.

 

 

Similar Threads

  1. v139h Internal Link Question
    By traytray in forum General Questions
    Replies: 10
    Last Post: 2 Jul 2013, 01:08 AM
  2. Internal link in footer
    By rrzc in forum General Questions
    Replies: 1
    Last Post: 16 Aug 2010, 07:00 PM
  3. Number of products by category link
    By kaitshel in forum Templates, Stylesheets, Page Layout
    Replies: 3
    Last Post: 25 Dec 2008, 05:53 PM
  4. mod_rewrite: maximum number of internal redirects reached.
    By kehrli in forum General Questions
    Replies: 3
    Last Post: 16 Nov 2007, 08:10 AM
  5. Internal link
    By amopro in forum All Other Contributions/Addons
    Replies: 3
    Last Post: 20 Feb 2007, 05:06 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