Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Infobox for specific category only


Guest

Recommended Posts

I'm sure there is a way to do this in column_left.php (or right) I'm just php impaired.

 

Basically, what I need is an infobox to appear ONLY when visiting category 44 or any products/sub categories within' cat. 44. I'd like to use it as a whole separate set of links (Privacy Policy, Testimonials, etc)

 

Any help would be appreciated.

 

Thanks,

Amanda

http://www.bellawyndmountain.com

Link to comment
Share on other sites

  • 4 weeks later...

Presuming that you have already created the new infobox, and also presuming that you named it santa.php, this will get you partway there. This code, added to either column_left.php or column_right.php will make your "santa.php" infobox appear when category 44 is clicked on. I haven't worked out yet how to get it to stay there within the subcats, though.

 

 

  if ($cPath == '44'){
 include(DIR_WS_BOXES . 'santa.php'); 
 } else {
 
 }

They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety. ~ Benjamin Franklin, 1759. տլ

Link to comment
Share on other sites

Got it! It may look ugly, but it works:

 

// show a special infobox if in category 44 or subcategory
if (($category_depth == 'nested') && ($cPath == '44'))  {
include(DIR_WS_BOXES . 'santa.php');
} else {
// if the cPath variable begins with 44_ show the santa box
if (ereg('[44_]', $cPath)) {
include(DIR_WS_BOXES . 'santa.php'); 
} else {
// do not show the santa box
}
}

 

(code commented to show what it's doing)

They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety. ~ Benjamin Franklin, 1759. տլ

Link to comment
Share on other sites

Ok.. got some strange things happening now. It APPEARS to me that the new "santa.php" menu shows up on all categories that have the number 4 in them (ie: 34, 46, 42) This could be just a coincidence on my end but I cleared my cache, etc. and it still seems to pop up under those categories. Everything else that it's supposed to do works fine, like appearing in subcategories.

 

Any idea what could cause this? I've left the addition in place so you could view it yourself: http://www.bellawyndmountain.com Bounce around through the categories.

 

Thanks for all of your help!

Amanda

Link to comment
Share on other sites

It work but I am a little disoriented because of the menu category box changes ...don't know what to expect after click on the category link. Nice mod. I will gave it a try. Thanks for the code Mary.

Link to comment
Share on other sites

I dont plan on leaving the menu in that spot when it's done.. just need to get it so it only shows when viewing category 44 and not other categories *containing* the number 4 :-)

 

 

Amanda

Link to comment
Share on other sites

How about this?

 

if ($cPath == '44' || substr($cPath, 0, 3) == '44_') {

include(DIR_WS_BOXES . 'santa.php');

}

** Please do not PM with personal support requests (even if offering "payment"). Thank you.

Link to comment
Share on other sites

Cool! Thanks Nate! I'm just getting started learning PHP, and had no idea what to do with the code after I got it that far. I'm glad you were here to help!

They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety. ~ Benjamin Franklin, 1759. տլ

Link to comment
Share on other sites

Just a side note - this little trick is a great thing when you want to add special images, or anything else, for certain categories.

 

Using the same code from nate I created new infobox containing only an image link, then copied the "categories_left.php" and renamed it. In the renamed file I took out everything except nates code and directed it to the new infobox I made.

 

Then I added the "require" code to where I wanted the new box to appear in category 44. If you look at my site you'll see that the image "Creating smiles for 7 years and counting!" only appears in category 44 & subcategories.

 

:-) Amanda

Link to comment
Share on other sites

Reminds me of a cheesy hack I did to an osC2.1 site - to the index.php to include an extra file at the tops of category pages to include an extra blurb or custom text for that category (checking first to see if the include file existed):

 

<?

// Insert custom HTML for category if file exists - cPath.html	

if (file_exists(DIR_WS_CUSTOM . $cPath . '.html'))  {

   // Include it
   echo '<tr><td>';
   include(DIR_WS_CUSTOM . $cPath . '.html');
   echo '</td></tr>';
   } 	 

?>

HTML "snippets" named 44_43.html etc... would be created and placed in a specified directory and would appear at the tops of category listing pages providing extra details about the product line, sales, etc...

** Please do not PM with personal support requests (even if offering "payment"). Thank you.

Link to comment
Share on other sites

  • 3 years later...

Hi everyone,

 

Well I've nearly finished my first oscommerce site but I'm having trouble getting nate's code to work fully.

 

 

if ($cPath == '44' || substr($cPath, 0, 3) == '44_') {

include(DIR_WS_BOXES . 'santa.php');

}

 

"santa.php" displays fine on the first category page of 44, but doesn't then appear in any of it's sub categories so I'm wondering if there is anything I need to alter in the piece of code: substr($cPath, 0, 3). Could anyone tell me what the 0,3 means please?

 

Any help would be most appreciated. Thanks all.

Link to comment
Share on other sites

PHP.NET for future... :)

substr

(PHP 4, PHP 5)

 

substr — Return part of a string

 

Description

string substr ( string $string, int $start [, int $length] )

 

Returns the portion of string specified by the start and length parameters.

 

Parameters

 

string

The input string.

 

start

If start is non-negative, the returned string will start at the start'th position in string, counting from zero. For instance, in the string 'abcdef', the character at position 0 is 'a', the character at position 2 is 'c', and so forth.

 

If start is negative, the returned string will start at the start'th character from the end of string.

 

 

Example 2462. Using a negative start

 

<?php

$rest = substr("abcdef", -1); // returns "f"

$rest = substr("abcdef", -2); // returns "ef"

$rest = substr("abcdef", -3, 1); // returns "d"

?>

 

 

 

length

If length is given and is positive, the string returned will contain at most length characters beginning from start (depending on the length of string). If string is less than or equal to start characters long, FALSE will be returned.

 

If length is given and is negative, then that many characters will be omitted from the end of string (after the start position has been calculated when a start is negative). If start denotes a position beyond this truncation, an empty string will be returned.

Best Regards,
Gaurav

Link to comment
Share on other sites

Thank you very much Gaurav - problem sorted!

 

What I was doing was testing the code with the category as cPath=2 but leaving the php coding as substr($cPath, 0, 3) when it should have been substr($cPath, 0, 2). Not really up to scratch on php but learning something new everyday!

 

Cheers again.

Link to comment
Share on other sites

  • 1 month later...
  • 1 year later...
Reminds me of a cheesy hack I did to an osC2.1 site - to the index.php to include an extra file at the tops of category pages to include an extra blurb or custom text for that category (checking first to see if the include file existed):

 

<?

// Insert custom HTML for category if file exists - cPath.html	

if (file_exists(DIR_WS_CUSTOM . $cPath . '.html'))  {

   // Include it
   echo '<tr><td>';
   include(DIR_WS_CUSTOM . $cPath . '.html');
   echo '</td></tr>';
   } 	 

?>

HTML "snippets" named 44_43.html etc... would be created and placed in a specified directory and would appear at the tops of category listing pages providing extra details about the product line, sales, etc...

 

nate - thanks - this is exactly what I needed to insert a gallery on my PRODUCT_INFO page. I wanted the gallery called to vary by category

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...