Black Belt
- Join Date:
- Jul 2005
- Location:
- Upstate NY
- Posts:
- 21,876
- Plugin Contributions:
- 8
Show/Hide sideboxes based on page
If you just add comment marks // in front of the top if and the bottom } , it will work.
Views: 43,781
Black Belt
If you just add comment marks // in front of the top if and the bottom } , it will work.
Totally Zenned
Here's what I have now:
<?php
//
// +----------------------------------------------------------------------+
// |zen-cart Open Source E-commerce |
// +----------------------------------------------------------------------+
// | Copyright (c) 2003 The zen-cart developers |
// | |
// | [url]http://www.zen-cart.com/index.php[/url] |
// | |
// | Portions Copyright (c) 2003 osCommerce |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the GPL license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available through the world-wide-web at the following url: |
// | [url]http://www.zen-cart.com/license/2_0.txt[/url]. |
// | If you did not receive a copy of the zen-cart license and are unable |
// | to obtain it through the world-wide-web, please send a note to |
// | [email protected] so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// $Id: login_box.php,v 1.0 2003/11/21 22:55:46 ajeh Exp $
//
// Designed for Zen Cart v1.00 Alpha
// Created by: Linda McGrath [email protected]
// [url]http://www.thewebmakerscorner.com[/url]
// Edited by: Ian Manson [email protected] 2006 08 13
// to include my account links when actually logged in
// show box when not logged in, and not when login/create account/forgot password pages are showing
// change title of box when logged in
//if (($_GET['main_page'] != FILENAME_LOGIN && $_GET['main_page'] != FILENAME_CREATE_ACCOUNT && $_GET['main_page'] != FILENAME_PASSWORD_FORGOTTEN)) {
$login_box[] = TEXT_LOGIN_BOX;
if ((!$_SESSION['customer_id'])) {
$title = BOX_HEADING_LOGIN_BOX;
} else {
$title = BOX_HEADING_LOGGEDIN_BOX;
}
require($template->get_template_dir('tpl_login_box.php',DIR_WS_TEMPLATE, $current_page_base,'sideboxes'). '/tpl_login_box.php');
$title_link = false;
require($template->get_template_dir($column_box_default, DIR_WS_TEMPLATE, $current_page_base,'common') . '/' . $column_box_default);
//}
?>
It makes no difference...
Black Belt
If that makes no difference, then you are editing the wrong copy of the file, or it otherwise is not getting saved to the right place.
What you posted has stray bits of code. Make sure these red bits are not in the actual file:
At the top
http://www.zen-cart.com/index.php |
At the bottom
?>">
Totally Zenned
!! Sorry!! I didn't even think about that. You're right, I was in the wrong copy.
And it worked. Thank you so much!!
You're amazing!
Black Belt
Glad you got it sorted!
New Zenner
Hi, I've read the entire thread and found no answer to my question.
I want to display a certain sidebox on all product pages and subcategory pages within a master category.
I've tried:
if($_GET['master_category'] == 10) {
...
}
and
if($current_category_id == 10) {
...
}
First one doesn't work at all, second one works only for the main category page, not for subcategories listing or product pages.
Can anyone help with this please?
Oba-san
Let's clarify a bit what a categories_id, $cPath, master_categories_id and $current_category_id really are ...
The Master Category is the master_categories_id of a Product in the products table ...
This is not the Top level Category it is the immediate Category that the Product is in ...
$cPath is the navigated Category path to where you are at from the Top down to through the subcategories ...
The $current_category_id is the immediate categories_id that you are in ...
If you are trying to build something where the $current_category_id is used, the $current_category_id is the immediate Category you are in ...
If you have your Categories as:
Category A categories_id = 3 $cPath = 3 $current_category_id = 3
|-- Category B categories_id = 10 $cPath - 3_10 $current_category_id = 10
|---- Categories C categories_id = 27 $cPath = 3_10_27 $current_category_id = 27
Products would not be in any of these Categories except for Category C, as Categories hold either Categories or Products, never both ...
If you are not using Linked Products, the the Products in Category 27 are all using Category 27 as the master_categories_id 27 ...
If you are using Linked Products, then the Product belongs to 2 or more Categories ... and the master_categories_id determines which of the multiple Categories is the "main" Category for the Product or the Category that "owns" the Product for things like putting a Category on Sale and if all Products in a Category is on Sale, that would mean that these Products use a master_categories_id that matches this categories_id ...
So if you want to see this for when in Category A, Category B and Category C ... use the $current_category_id for all 3 such as:
if($current_category_id == 3 || $current_category_id == 10 || $current_category_id == 27) {
Now, as you navigate through that branch of the Category tree, you see it for all 3 levels ...
New Zenner
Wow thanks a lot Ajeh for the comprehensive answer, now I understand I was mixing them together :blush:
If I have many subcategories, would it be faster to use:
if (in_array($current_category_id, array('1', '2','3', '4', 'etc'))) {
}
What I'm trying to do is display the subcategories of a top level category inside all of its pages. Kind of like category sidebox with always open to show subcategories=1, but without the top level categories links.
I started a thread for this , but since it seems hard to tackle the category_tree.php class, I was thinking to do something similar with around 10 editable sideboxes, with conditions such as the above and define the links for each one.
Which one seems easier? :flex:
Oba-san
The in_array is a lot faster to work with and should be much easier to manage ...
You could probably customize the categories box to another sidebox and put these conditions into it ...
Perhaps someone who has tried something similar would have a solution or idea on this ...
New Zenner
This is the closest answer I could get but I must be missing something. I created a new sidebox blank_sidebox, and would like it to show on category description pages, product list page, and the product page only. I think Svanis' code (page 2 of this thread) was intended to do this, but it did not work for me. Maybe I'm missing something because his code was split in a confusing way?
Oba-san
See if this helps ...
if ($current_category_id > 0 || $_GET['main_page'] == 'product_info') {
$show_this_box = true;
} else {
$show_this_box = false;
}
New Zenner
Thanks for the quick reply, but I'm still not getting it, for my situation I'm editing includes/modules/sideboxes/MY TEMPLATE/blank_sidebox.php and now have the following code:
<?php
// test if box should display
$show_blank_sidebox = true;
if ($current_category_id > 0 || $_GET['main_page'] == 'product_info') {
$show_blank_sidebox = true;
} else {
$show_blank_sidebox = false;
}
if ($show_blank_sidebox == true) {
require($template->get_template_dir('tpl_blank_sidebox.php',DIR_WS_TEMPLATE, $current_page_base,'sideboxes'). '/tpl_blank_sidebox.php');
$title = BOX_HEADING_BLANK_SIDEBOX;
$title_link = false;
require($template->get_template_dir($column_box_default, DIR_WS_TEMPLATE, $current_page_base,'common') . '/' . $column_box_default);
}
?>
Ajeh:
See if this helps ...
if ($current_category_id > 0 || $_GET['main_page'] == 'product_info') {
$show_this_box = true;
} else {
$show_this_box = false;
}
Oba-san
You indicated that you want this to show when you are navigating the Categories ... and the product _info pages ...
I see this only if I am navigating through the Category tree ... or if I am on the product _info page ...
First, test what happens if you make both parts of the IF true ... do you always see the sidebox?
Next, set the false back in there and go to the home page ... as there isn't a selected Category, you will not see the sidebox ...
Next, click on a Category, and you should see the sidebox ...
Now, click on a Product and you should see the sidebox ...
Is this how you are wanting it to work? :unsure:
New Zenner
Ajeh:
First, test what happens if you make both parts of the IF true ... do you always see the sidebox?
Next, set the false back in there and go to the home page ... as there isn't a selected Category, you will not see the sidebox ...
Next, click on a Category, and you should see the sidebox ...
Now, click on a Product and you should see the sidebox ...
You're accurate, that this should only display on those pages, the sidebox is a subcategory navigation dropbox system, so it does not need to be on the front page or pages such as add to cart, checkout, etc...
I had previously added the following code to tpl_main_page.php to at minimum stop it from loading on the page. (per a suggestion in this thread.)
if ($this_is_home_page == true) {
$flag_disable_left = true;
$flag_disable_right = true;
}
To test things out further, I removed that code to start clean and then went back to the blank_sidebox.php we've been discussing and tested the if statements per your suggestion. I feel like I'm really missing something obvious now, because regardless of if both are true or both are false, the sidebox is still loading. I feel like I'm working on the wrong file, even though I'm sure I'm not, but just to re-confirm I tested on both the original and over-ride file. :no:
New Zenner
Quick correction, I can get the side box to be on all pages or no pages by editing the true/false or even reversing them. I had a silly error when I copied back in your code suggestion I forgot to change to $show_blank_sidebox, but in any case I still can't get it to only show on the pages discussed.
Oba-san
Could you go to the Tools ... Developers Tool Kit ... and in the bottom input box enter:
$show_blank_sidebox
What files come up?
If you look at that file on the server, what does the code read?
New Zenner
Error: No matching Configuration Keys were found ... $show_blank_sidebox
I had added this sidebox from the blank sidebox addon at http://www.zen-cart.com/index.php?main_page=product_contrib_info&products_id=174
Black Belt
Did you change the blank_sidebox name to something else? If so, that would be the code to search for.
New Zenner
No I left everything as is. Just using it to develop an add-on, so there was no need to do anything. :-/
I'll go double check I didn't post any portion of it in the wrong location, because multi-site mod is also installed, so it's easier to make a mistake on folders.
Oba-san
Could you peek in the Tools ... Layout Boxes Controller ... and ensure that this sidebox is turned on ...
What is the path on that sidebox?
When you searched in the Tools ... Developers Tool Kit ... in the bottom input box on:
$show_blank_sidebox
did you select Catalog from the dropdown and then click search?
Tell staff why this post should be reviewed.