nevmic Posted June 23, 2007 Posted June 23, 2007 I would like that a banner on top of the shop (within header) changes according to category as follows: 1) If it is within any other page then I have a default banner. 2) If it is within a category I want to show the banner associated with that category (same image uploaded from admin). 3) If it is within a subcategory I want to still show the banner associated with that category. 4) If it is within a product page I want to still show the banner associated with that category. 1) OK 2) OK Code used: if ($category_depth == 'nested') { $category_query = tep_db_query("select c.categories_image from " . TABLE_CATEGORIES . " c where c.categories_id = '" . (int)$current_category_id . "'"); $category = tep_db_fetch_array($category_query); echo tep_image(DIR_WS_IMAGES . $category['categories_image'], "ALT", 768, 130); 3) I need to extract the parent_id from the subcategory for this to work but I cannot manage: elseif ($category_depth == 'products') { $category_query = tep_db_query("select c.product_id, c.categories_image from " . TABLE_CATEGORIES . " c where c.categories_id = '" . (int)product_id . "'"); } 4) no idea so far I would appreciate some help to solve points 3 & 4 Thanks
nevmic Posted June 23, 2007 Author Posted June 23, 2007 I solved this issue with my limited php/mysql. I am sure there is a cleaner way to do it... but in the meantime it works fine. If you have any suggextions, please let me know. //if within a category if ($category_depth == 'nested') { $category_query = tep_db_query("select c.categories_image from " . TABLE_CATEGORIES . " c where c.categories_id = '" . (int)$current_category_id . "'"); $category = tep_db_fetch_array($category_query); echo tep_image(DIR_WS_IMAGES . $category['categories_image'], STORE_NAME, 768, 130); // if within subcategory } elseif ($category_depth == 'products') { $parent_query = tep_db_query("select parent_id from " . TABLE_CATEGORIES . " where categories_id = '" . (int)$current_category_id . "'"); $parent = tep_db_fetch_array($parent_query); $category_query = tep_db_query("select c.categories_image from " . TABLE_CATEGORIES . " c where c.categories_id = '" . $parent['parent_id'] . "'"); $category = tep_db_fetch_array($category_query); echo tep_image(DIR_WS_IMAGES . $category['categories_image'], STORE_NAME, 768, 130); // if within product page } elseif ($_GET['pID']){ $cat_query = tep_db_query("select categories_id from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . $_GET['pID'] . "'"); $cat = tep_db_fetch_array($cat_query); $parent_query = tep_db_query("select parent_id from " . TABLE_CATEGORIES . " where categories_id = '" . $cat['categories_id'] . "'"); $parent = tep_db_fetch_array($parent_query); $category_query = tep_db_query("select c.categories_image from " . TABLE_CATEGORIES . " c where c.categories_id = '" . $parent['parent_id'] . "'"); $category = tep_db_fetch_array($category_query); echo tep_image(DIR_WS_IMAGES . $category['categories_image'], STORE_NAME, 768, 130); } else { //whatever } Thanks
Jack_mcs Posted June 23, 2007 Posted June 23, 2007 Probably using the in-built function tep_get_parent_categories is better than writing new code. Jack Support Links: For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc. All of My Addons Get the latest versions of my addons Recommended SEO Addons
nevmic Posted June 23, 2007 Author Posted June 23, 2007 Probably using the in-built function tep_get_parent_categories is better than writing new code. Jack Interesting! I found the function but did not find 1 simple example on how to use it. Tried this echo tep_get_parent_categories($category, (int)$current_category_id); with no luck! I am not sure what to place instead of $category. Thanks!
Jack_mcs Posted June 23, 2007 Posted June 23, 2007 The first argument is an empty array. See tep_get_product_path in the same file for an example. Jack Support Links: For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc. All of My Addons Get the latest versions of my addons Recommended SEO Addons
nevmic Posted June 23, 2007 Author Posted June 23, 2007 The first argument is an empty array. See tep_get_product_path in the same file for an example. Jack Thanks for your help but I do not understand. I cannot even understand what the function is returning.... or I blieve it just returns 'true' when it finds the parent category. I just want to get this 'categories_image' of the category (not sub-category) and have no idea how to use that function to find it!
Jack_mcs Posted June 23, 2007 Posted June 23, 2007 It returns an array of categories. You will need to research a php site to understand how arrays work since it is beyond the scope of this forum. Jack Support Links: For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc. All of My Addons Get the latest versions of my addons Recommended SEO Addons
Recommended Posts
Archived
This topic is now archived and is closed to further replies.