Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Customize category links


madsjarner

Recommended Posts

Posted

I could not find this elsewhere, so after I have found a solution for my problem, I would like to post it here so other users may benefit from it.

 

My problem was that I would like to get one of the categories in the left side to link to another place than the standard category-list.

 

To do this, change the following in /catalog/includes/boxes/categories.php

 

$categories_string .= ' href="'.tep_href_link(FILENAME_DEFAULT, $cPath_new);

 

to

 

 if ($tree[$counter]['path'] == 26) {
     $categories_string .= ' href="'.'your new link path here';
   } else {
     $categories_string .= ' href="'.tep_href_link(FILENAME_DEFAULT, $cPath_new);
   }

 

where 26 here is an example of the .../index.php?cPath=26

 

Then you can do this for every path number that you wish, just add another 'else if'-sentence and another category path number.

  • 3 months later...
Posted
I could not find this elsewhere, so after I have found a solution for my problem, I would like to post it here so other users may benefit from it.

 

My problem was that I would like to get one of the categories in the left side to link to another place than the standard category-list.

 

To do this, change the following in /catalog/includes/boxes/categories.php

 

$categories_string .= ' href="'.tep_href_link(FILENAME_DEFAULT, $cPath_new);

 

to

 

 if ($tree[$counter]['path'] == 26) {
     $categories_string .= ' href="'.'your new link path here';
   } else {
     $categories_string .= ' href="'.tep_href_link(FILENAME_DEFAULT, $cPath_new);
   }

 

where 26 here is an example of the .../index.php?cPath=26

 

Then you can do this for every path number that you wish, just add another 'else if'-sentence and another category path number.

 

For some reason, this is not working for me. Here is my code. I get a box around my image next to the category, the category name disappears and the link seems to be incorrect (catalog/href=) Please help me fix this problem.

 

<?php
/*
 $Id: categories.php,v 1.25 2003/07/09 01:13:58 hpdl Exp $

 E-Commerce Solutions

 Copyright © 2005 www.flash-template-design.com

 Released under the GNU General Public License
*/

 function tep_show_category($counter) {
   global $tree, $categories_string, $cPath_array;

  for ($i=0; $i<$tree[$counter]['level']; $i++) {
     $categories_string .= "  ";
   }
$categories_string .= '<img src="images/sign_link.jpg" width="13" height="14">  <a class="m11" href="';
if ($tree[$counter]['parent'] == 0) {
     $cPath_new = 'cPath=' . $counter;
   } else {
     $cPath_new = 'cPath=' . $tree[$counter]['path'];
   }
  if ($tree[$counter]['path'] == 36) {      $categories_string .= ' href="'.'your new link path here';    } else { $categories_string .= tep_href_link(FILENAME_COLLECTION, $cPath_new) . '">'; 
} 

if (isset($cPath_array) && in_array($counter, $cPath_array)) {
     $categories_string .= '<span style="font-weight:bold; text-decoration:underline; color:#FF0000">';
   }

// display category name
   $categories_string .= $tree[$counter]['name'];

   if (isset($cPath_array) && in_array($counter, $cPath_array)) {
     $categories_string .= '</span>';
   }

  // if (tep_has_category_subcategories($counter)) {
  //   $categories_string .= '->';
   // }

   $categories_string .= '</a>';

   if (SHOW_COUNTS == 'true') {
     $products_in_category = tep_count_products_in_category($counter);
     if ($products_in_category > 0) {
       $categories_string .= '<span style="color:#E80377"> (' . $products_in_category . ')</span>';
     }
   }

   $categories_string .= '<br/>';


   if ($tree[$counter]['next_id'] != false) {
     tep_show_category($tree[$counter]['next_id']);
   }
 }
?>
<!-- categories //-->

<table width="80%" cellpadding="0" cellspacing="10" border="0">
<tr>        
	<td align="left">
<?php
 $info_box_contents = array();

 $info_box_contents[] = array('text' => BOX_HEADING_CATEGORIES);
?>

<?php
 $categories_string = '';
 $tree = array();

 $categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id 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)$languages_id ."' order by sort_order, cd.categories_name");
 while ($categories = tep_db_fetch_array($categories_query))  {
   $tree[$categories['categories_id']] = array('name' => $categories['categories_name'],
                                               'parent' => $categories['parent_id'],
                                               'level' => 0,
                                               'path' => $categories['categories_id'],
                                               'next_id' => false);

   if (isset($parent_id)) {
     $tree[$parent_id]['next_id'] = $categories['categories_id'];
   }

   $parent_id = $categories['categories_id'];

   if (!isset($first_element)) {
     $first_element = $categories['categories_id'];
   }
 }
//------------------------
 if (tep_not_null($cPath)) {
   $new_path = '';
   reset($cPath_array);
   while (list($key, $value) = each($cPath_array)) {
     unset($parent_id);
     unset($first_id);
     $categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '" . (int)$value . "' and c.categories_id = cd.categories_id and cd.language_id='" . (int)$languages_id ."' order by sort_order, cd.categories_name");
     if (tep_db_num_rows($categories_query)) {
       $new_path .= $value;
       while ($row = tep_db_fetch_array($categories_query)) {
         $tree[$row['categories_id']] = array('name' => $row['categories_name'],
                                              'parent' => $row['parent_id'],
                                              'level' => $key+1,
                                              'path' => $new_path . '_' . $row['categories_id'],
                                              'next_id' => false);

         if (isset($parent_id)) {
           $tree[$parent_id]['next_id'] = $row['categories_id'];
         }

         $parent_id = $row['categories_id'];

         if (!isset($first_id)) {
           $first_id = $row['categories_id'];
         }

         $last_id = $row['categories_id'];
       }
       $tree[$last_id]['next_id'] = $tree[$value]['next_id'];
       $tree[$value]['next_id'] = $first_id;
       $new_path .= '_';
     } else {
       break;
     }
   }
 }

 tep_show_category($first_element); 

 $info_box_contents = array();
 $info_box_contents[] = array('text' => $categories_string);
?>

 <?php
 new infoBox($info_box_contents);
?>
</td></tr></table>


 <!-- categories_eof //-->

Posted

There is a problem with this code, you removes the tep_href_link on the custom link, this will cause of loss of sid if not forceing cookies, the code you should use is:

 

 

 

 if ($tree[$counter]['path'] == 26) {
     $categories_string .= ' href="'.tep_href_link('MyLink');
   } else {
     $categories_string .= ' href="'.tep_href_link(FILENAME_DEFAULT, $cPath_new);
   }

Sam

 

Remember, What you think I ment may not be what I thought I ment when I said it.

 

Contributions:

 

Auto Backup your Database, Easy way

 

Multi Images with Fancy Pop-ups, Easy way

 

Products in columns with multi buy etc etc

 

Disable any Category or Product, Easy way

 

Secure & Improve your account pages et al.

  • 5 months later...
Posted

Nice...thanks for the info. I used this, although I had to use this version to work:

if ($tree[$counter]['path'] == 34) {
$categories_string .= tep_href_link('about_us.php', $cPath_new) . '>';
} else {
$categories_string .= tep_href_link('index.php', $cPath_new) . '>';
 }

 

This works perfectly now (woohoo!), but I've tried adding a second category as a link, and no luck. I get all kinds of errors. Anyone got a way for me to add another link to this code?

I'm trying to make the php?cPath=35 link to my shipping.php

 

Thanks,

zOnk

Posted

Figured it out...here's the solution if anyone needs this in the future:

 

if ($tree[$counter]['path'] == 34) {
$categories_string .= tep_href_link('about_us.php', $cPath_new) . '>';
} 
elseif ($tree[$counter]['path'] == 35) {
$categories_string .= tep_href_link('shipping.php', $cPath_new) . '>';
} else {
$categories_string .= tep_href_link('index.php', $cPath_new) . '>';
 }

  • 1 year later...
Posted

Figured it out...here's the solution if anyone needs this in the future:

 

if ($tree[$counter]['path'] == 34) {
$categories_string .= tep_href_link('about_us.php', $cPath_new) . '>';
} 
elseif ($tree[$counter]['path'] == 35) {
$categories_string .= tep_href_link('shipping.php', $cPath_new) . '>';
} else {
$categories_string .= tep_href_link('index.php', $cPath_new) . '>';
 }

 

Hi I was wondering if someone can help me do this for my site my code is from a template so I understand it not standard form

 

Here is my code

 

$categories_string .= '<a href="';

 

if ($tree[$counter]['parent'] == 0) {

$cPath_new = 'cPath=' . $counter;

} else {

$cPath_new = 'cPath=' . $tree[$counter]['path'];

}

 

$categories_string .= tep_href_link(FILENAME_DEFAULT, $cPath_new) . '">';

 

if (isset($cPath_array) && in_array($counter, $cPath_array)) {

$categories_string .= '<b>';

}

I am looking to add new links to the categories

 

any help would be great.

 

Cheers

 

Henry

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...