Zen Cart Logo
Forums / General Questions / Show/Hide sideboxes based on page

Show/Hide sideboxes based on page

Views: 43,781

Results 141 to 160 of 189
27 Sep 2010, 10:25 PM
#141
gjh42 avatar

gjh42

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.

27 Sep 2010, 10:59 PM
#142
joyjoy avatar

joyjoy

Totally Zenned

Join Date:
Sep 2010
Posts:
611
Plugin Contributions:
0

Re: Show/Hide sideboxes based on page

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

27 Sep 2010, 11:05 PM
#143
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Show/Hide sideboxes based on page

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

27 Sep 2010, 11:08 PM
#144
joyjoy avatar

joyjoy

Totally Zenned

Join Date:
Sep 2010
Posts:
611
Plugin Contributions:
0

Re: Show/Hide sideboxes based on page

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

27 Sep 2010, 11:10 PM
#145
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Show/Hide sideboxes based on page

Glad you got it sorted!

25 Oct 2010, 6:40 AM
#146
kidsstuff avatar

kidsstuff

New Zenner

Join Date:
Oct 2010
Posts:
44
Plugin Contributions:
0

Re: Show/Hide sideboxes based on page

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?

25 Oct 2010, 1:43 PM
#147
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Show/Hide sideboxes based on page

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

25 Oct 2010, 3:29 PM
#148
kidsstuff avatar

kidsstuff

New Zenner

Join Date:
Oct 2010
Posts:
44
Plugin Contributions:
0

Re: Show/Hide sideboxes based on page

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:

25 Oct 2010, 4:33 PM
#149
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Show/Hide sideboxes based on page

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

29 Oct 2010, 4:55 AM
#150
byoriginaldesign avatar

byoriginaldesign

New Zenner

Join Date:
Apr 2009
Posts:
84
Plugin Contributions:
0

Re: Show/Hide sideboxes based on page

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?

29 Oct 2010, 5:17 AM
#151
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Show/Hide sideboxes based on page

See if this helps ...

if ($current_category_id > 0 || $_GET['main_page'] == 'product_info') {
  $show_this_box = true;
} else {
  $show_this_box = false;
}
29 Oct 2010, 5:35 AM
#152
byoriginaldesign avatar

byoriginaldesign

New Zenner

Join Date:
Apr 2009
Posts:
84
Plugin Contributions:
0

Re: Show/Hide sideboxes based on page

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;
}

29 Oct 2010, 1:30 PM
#153
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Show/Hide sideboxes based on page

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:

29 Oct 2010, 2:20 PM
#154
byoriginaldesign avatar

byoriginaldesign

New Zenner

Join Date:
Apr 2009
Posts:
84
Plugin Contributions:
0

Re: Show/Hide sideboxes based on page

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:

29 Oct 2010, 2:34 PM
#155
byoriginaldesign avatar

byoriginaldesign

New Zenner

Join Date:
Apr 2009
Posts:
84
Plugin Contributions:
0

Re: Show/Hide sideboxes based on page

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.

29 Oct 2010, 4:03 PM
#156
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Show/Hide sideboxes based on page

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?

29 Oct 2010, 4:33 PM
#158
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Show/Hide sideboxes based on page

Did you change the blank_sidebox name to something else? If so, that would be the code to search for.

29 Oct 2010, 4:35 PM
#159
byoriginaldesign avatar

byoriginaldesign

New Zenner

Join Date:
Apr 2009
Posts:
84
Plugin Contributions:
0

Re: Show/Hide sideboxes based on page

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.

29 Oct 2010, 4:49 PM
#160
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Show/Hide sideboxes based on page

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?