Forums / General Questions / internal link to category number

internal link to category number

Views: 1,583

Results 1 to 10 of 10
1 Nov 2015, 3:52 AM
#1
vanhorn_s avatar

vanhorn_s

Zen Follower

Join Date:
Apr 2010
Posts:
283
Plugin Contributions:
0

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?

1 Nov 2015, 7:23 AM
#3
lhungil avatar

lhungil

Totally Zenned

Join Date:
Feb 2012
Location:
mostly harmless
Posts:
1,818
Plugin Contributions:
4

Re: internal link to category number

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

PHPDocs for zen_href_link:

	/**
	 * 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:

# 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".

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

1 Nov 2015, 7:49 AM
#4
lhungil avatar

lhungil

Totally Zenned

Join Date:
Feb 2012
Location:
mostly harmless
Posts:
1,818
Plugin Contributions:
4

Re: internal link to category number

Design75:

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

1 Nov 2015, 5:18 PM
#5
vanhorn_s avatar

vanhorn_s

Zen Follower

Join Date:
Apr 2010
Posts:
283
Plugin Contributions:
0

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

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

1 Nov 2015, 5:36 PM
#6
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: internal link to category number

vanhorn_s:

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

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

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

1 Nov 2015, 6:04 PM
#7
vanhorn_s avatar

vanhorn_s

Zen Follower

Join Date:
Apr 2010
Posts:
283
Plugin Contributions:
0

Re: internal link to category number

mc12345678:

Umm.. Are you painstakingly manually entering each of the category entries below?

 		 			 			 				<?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>
1 Nov 2015, 6:06 PM
#8
vanhorn_s avatar

vanhorn_s

Zen Follower

Join Date:
Apr 2010
Posts:
283
Plugin Contributions:
0

Re: internal link to category number

I also added to the jquery_jpanel.js file for each menu.

		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;
		}
	});
2 Nov 2015, 3:52 PM
#9
vanhorn_s avatar

vanhorn_s

Zen Follower

Join Date:
Apr 2010
Posts:
283
Plugin Contributions:
0

Re: internal link to category number

mc12345678:

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.

7 Nov 2015, 8:31 PM
#10
lindasdd avatar

lindasdd

Zen Follower

Join Date:
Jun 2007
Posts:
474
Plugin Contributions:
0

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.