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

Show/Hide sideboxes based on page

Views: 43,781

Results 61 to 80 of 189
20 Nov 2008, 2:24 PM
#61
js5729 avatar

js5729

New Zenner

Join Date:
Jul 2007
Location:
Germany
Posts:
21
Plugin Contributions:
0

Show/Hide sideboxes based on page

Thanks for this. I was looking for exactly the same thing and this works perfectly.

anniti:

sorry, I got confused,
for the productpages, you'd need:

// test if box should display

$show_my_sidebox = false;
if ($_GET['main_page']=='product_info') {
$show_my_sidebox = true;
}

31 Jan 2009, 7:36 PM
#62
ctcentralinfo avatar

ctcentralinfo

Totally Zenned

Join Date:
Apr 2005
Posts:
853
Plugin Contributions:
0

Re: Show/Hide sideboxes based on page

So far I have been able to hide the stock sideboxes using the message in the above post, for certain pages I do not want them to show up on yet cannot seem to get it to work for the following side boxes:

testimonials

<?php /** * testimonials sidebox * * @package templateSystem * @copyright Copyright 2006 Nicholas Keown * @copyright Portions Copyright 2003-2005 Zen Cart Development Team * @copyright Portions Copyright 2003 osCommerce * @license <http://www.zen-cart.com/license/2_0.txt> GNU Public License V2.0 * @version $Id: testimonials.php 2006-10-27 [email protected] $ */ if (TESTIMONIALS_BOX_ORDER_BY == 'random') { $testimonials_order = 'rand(), testimonials_id'; } else { $testimonials_order = 'testimonials_sticky ASC, testimonials_date_added DESC'; } // in case another process uses this var if (isset($page_query)) unset($page_query); if (TESTIMONIALS_BOX_SHOW_BY_PRODUCT != 'never') { if (TESTIMONIALS_BOX_SHOW_BY_PRODUCT == 'product' && isset($_GET['products_id'])) { // just by product $page_query = $db->Execute('SELECT testimonials_id, testimonials_title, testimonials_name, testimonials_organisation, testimonials_town, testimonials_country, testimonials_web_address, testimonials_obfuscate_url, testimonials_html_text FROM ' . TABLE_TESTIMONIALS . ' WHERE testimonials_status = 1 AND testimonials_products_id=' . (int)$_GET['products_id'] . ' AND testimonials_language_id=' . (int)$_SESSION['languages_id'] . ' ORDER BY ' . $testimonials_order . ' LIMIT ' . (int)TESTIMONIALS_BOX_MAX_DISPLAY); } if ((TESTIMONIALS_BOX_SHOW_BY_PRODUCT == 'category' || TESTIMONIALS_BOX_SHOW_BY_PRODUCT == 'preferred') && isset($current_category_id) && $current_category_id > 0) { // this includes all in a category $page_query = $db->Execute('SELECT DISTINCT t.testimonials_id, t.testimonials_title, t.testimonials_name, t.testimonials_organisation, t.testimonials_town, t.testimonials_country, t.testimonials_web_address, t.testimonials_obfuscate_url, t.testimonials_html_text FROM ' . TABLE_TESTIMONIALS . ' AS t, ' . TABLE_PRODUCTS_TO_CATEGORIES . ' AS ptc, ' . TABLE_CATEGORIES . ' AS c WHERE t.testimonials_status = 1 AND t.testimonials_products_id = ptc.products_id AND ptc.categories_id = c.categories_id AND t.testimonials_products_id > 0 AND ' . $current_category_id . ' IN (c.categories_id, c.parent_id) AND testimonials_language_id=' . (int)$_SESSION['languages_id'] . ' ORDER BY ' . $testimonials_order . ' LIMIT ' . (int)TESTIMONIALS_BOX_MAX_DISPLAY); } } if ((TESTIMONIALS_BOX_SHOW_BY_PRODUCT == 'preferred' && ((isset($page_query) && $page_query->RecordCount() === 0) || !isset($page_query))) || TESTIMONIALS_BOX_SHOW_BY_PRODUCT == 'never') { // do for all testimonials where there are none to show in hope of getting some, or admin wants all $page_query = $db->Execute('SELECT testimonials_id, testimonials_title, testimonials_name, testimonials_organisation, testimonials_town, testimonials_country, testimonials_web_address, testimonials_obfuscate_url, testimonials_html_text FROM ' . TABLE_TESTIMONIALS . ' WHERE testimonials_status = 1 AND testimonials_language_id=' . (int)$_SESSION['languages_id'] . ' ORDER BY ' . $testimonials_order . ' LIMIT ' . (int)TESTIMONIALS_BOX_MAX_DISPLAY); } if (isset($page_query) && $page_query->RecordCount() > 0) { $title = BOX_HEADING_TESTIMONIALS; $title_link = FILENAME_TESTIMONIALS; require ($template->get_template_dir('tpl_testimonials.php', DIR_WS_TEMPLATE, $current_page_base, 'sideboxes'). '/tpl_testimonials.php'); require ($template->get_template_dir($column_box_default, DIR_WS_TEMPLATE, $current_page_base, 'common') . '/' . $column_box_default); }

categories

<?php /** * categories sidebox - prepares content for the main categories sidebox * * @package templateSystem * @copyright Copyright 2003-2005 Zen Cart Development Team * @copyright Portions Copyright 2003 osCommerce * @license <http://www.zen-cart.com/license/2_0.txt> GNU Public License V2.0 * @version $Id: categories.php 2718 2005-12-28 06:42:39Z drbyte $ */ $main_category_tree = new category_tree; $row = 0; $box_categories_array = array(); // don't build a tree when no categories $check_categories = $db->Execute("select categories_id from " . TABLE_CATEGORIES . " where categories_status=1 limit 1"); if ($check_categories->RecordCount() > 0) { $box_categories_array = $main_category_tree->zen_category_tree(); } if (!isset($ezpage_id) || !in_array($ezpage_id,explode(",",'7,8,9,10,11,12,13,14,15,16,17,18'))) { require($template->get_template_dir('tpl_categories.php',DIR_WS_TEMPLATE, $current_page_base,'sideboxes'). '/tpl_categories.php'); $title = BOX_HEADING_CATEGORIES; $title_link = false; require($template->get_template_dir($column_box_default, DIR_WS_TEMPLATE, $current_page_base,'common') . '/' . $column_box_default); } ?>

Could anyone show me how I can use the code

// test if box should display

$show_my_sidebox = false;
if ($_GET['main_page']=='product_info') {
$show_my_sidebox = true;
}

To get the opposite effect?

1 Feb 2009, 4:36 AM
#63
ctcentralinfo avatar

ctcentralinfo

Totally Zenned

Join Date:
Apr 2005
Posts:
853
Plugin Contributions:
0

Re: Show/Hide sideboxes based on page

Any suggestions, the code is slightly different.

1 Feb 2009, 5:39 AM
#64
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

Since those sideboxes don't have the switch code built in, setting the flag won't do anything.
In these cases, you would use an adaptation of Kuroi's directions in post 51:

...wrap all the executable statements inside this condition

if ($_GET['main_page']=='product_info') {

//...

} 
1 Feb 2009, 7:21 PM
#65
ctcentralinfo avatar

ctcentralinfo

Totally Zenned

Join Date:
Apr 2005
Posts:
853
Plugin Contributions:
0

Re: Show/Hide sideboxes based on page

gjh42:

Since those sideboxes don't have the switch code built in, setting the flag won't do anything.
In these cases, you would use an adaptation of Kuroi's directions in post 51:

...wrap all the executable statements inside this condition

if ($_GET['main_page']=='product_info') {

//...

}


How can I add more than one page for them to show up on?
1 Feb 2009, 7:37 PM
#66
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

Duplicate the tests in the if() statement:```php
if ($_GET['main_page']=='product_info' or $_GET['main_page']=='product_listing') {

//...

}

If you have a bunch of pages to handle, you may want to switch over to the 
if(in_array($_GET['main_page'],explode(...
as described in the comments in tpl_main_page.php.
1 Feb 2009, 10:54 PM
#67
ctcentralinfo avatar

ctcentralinfo

Totally Zenned

Join Date:
Apr 2005
Posts:
853
Plugin Contributions:
0

Re: Show/Hide sideboxes based on page

Just to be sure, these are the pages I don't want those sideboxes to show up on:

about_cool_tech
cool_tech_values
inside_cool_tech
giving_back
think_green
tech_support
discount-coupon

using the code I should be able to block the sideboxes from these pages?

1 Feb 2009, 11:06 PM
#68
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

Yes, that's right.
Something like```php
if (in_array($current_page_base, explode(',','about_cool_tech,cool_tech_values,inside_cool_tech,giving_back,think_green,tech_support,discount-coupon'))){
//skip these pages
} else {

//...execute the code

}

1 Feb 2009, 11:07 PM
#69
ctcentralinfo avatar

ctcentralinfo

Totally Zenned

Join Date:
Apr 2005
Posts:
853
Plugin Contributions:
0

Re: Show/Hide sideboxes based on page

Edit: my bad, did read your new post.

So what to I rap the code around?

1 Feb 2009, 11:16 PM
#70
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 you want the sidebars to go away completely on those pages, you would put that in tpl_main_page.php, and use it to set $flag_disable_left and $flag_disable_right.```php
if (in_array($current_page_base, explode(',','about_cool_tech,cool_tech_values,inside_cool_tech,giving_back,think_green,tech_support,discount-coupon'))){
//skip these pages
$flag_disable_left = true;
$flag_disable_right = true;
} else {
$flag_disable_left = false;
$flag_disable_right = false;
}

This would go near the top of the file - look at it for guidance.
1 Feb 2009, 11:22 PM
#71
ctcentralinfo avatar

ctcentralinfo

Totally Zenned

Join Date:
Apr 2005
Posts:
853
Plugin Contributions:
0

Re: Show/Hide sideboxes based on page

gjh42:

If you want the sidebars to go away completely on those pages, you would put that in tpl_main_page.php, and use it to set $flag_disable_left and $flag_disable_right.```php
if (in_array($current_page_base, explode(',','about_cool_tech,cool_tech_values,inside_cool_tech,giving_back,think_green,tech_support,discount-coupon'))){
//skip these pages
$flag_disable_left = true;
$flag_disable_right = true;
} else {
$flag_disable_left = false;
$flag_disable_right = false;
}

> This would go near the top of the file - look at it for guidance.

I just wanted the categories and testimonials to not show up on the pages, I apologize for not being more specific.
1 Feb 2009, 11:41 PM
#72
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

Ah ok, in that case you would wrap the test around all of the executable code in the categories.php and testimonials.php module files, or possibly the tpl_ files, I don't recall which at the moment (check on their exact names).

Yes (post 62), categories.php and testimonials.php.

2 Feb 2009, 1:48 AM
#73
ctcentralinfo avatar

ctcentralinfo

Totally Zenned

Join Date:
Apr 2005
Posts:
853
Plugin Contributions:
0

Re: Show/Hide sideboxes based on page

Would the executable code be:

require ($template->get_template_dir('tpl_testimonials.php', DIR_WS_TEMPLATE, $current_page_base, 'sideboxes'). '/tpl_testimonials.php');
require ($template->get_template_dir($column_box_default, DIR_WS_TEMPLATE, $current_page_base, 'common') . '/' . $column_box_default);

For includes/modules/sideboxes/my_template/testimonials.php

and:

require($template->get_template_dir('tpl_categories.php',DIR_WS_TEMPLATE, $current_page_base,'sideboxes'). '/tpl_categories.php');

$title = BOX_HEADING_CATEGORIES;
$title_link = false;

require($template->get_template_dir($column_box_default, DIR_WS_TEMPLATE, $current_page_base,'common') . '/' . $column_box_default);
}

For includes/modules/sideboxes/my_template/categories.php

If so I rapped this bit of code around them:

if(in_array($_GET['main_page'],explode(',','about_cool_tech,cool_tech_values,inside_cool_tech,giving_back,think_green,tech_support,discount-coupon'))){
}

but it didn't work.

13 Jan 2010, 12:13 AM
#74
jdyach avatar

jdyach

New Zenner

Join Date:
Dec 2008
Posts:
6
Plugin Contributions:
0

Re: Show/Hide sideboxes based on page

dealbyethan.com:

Add this to tpl_main_page.php

$center_column_only = array('checkout');

Where in the page is this added?

19 Jan 2010, 5:22 PM
#75
kburner avatar

kburner

Totally Zenned

Join Date:
Apr 2008
Location:
Flint, Michigan
Posts:
684
Plugin Contributions:
0

Re: Show/Hide sideboxes based on page

I am somewhat confused with coding as I go through this thread.

My goal is to hide certain sideboxes from the product pages. But, do not see sideboxes for them. Sideboxes to hide: newsletter, links, testimonials, and About Us.

Which file? I think this may be code? Where should it go in file at?

if (in_array($current_page_base, explode(',','about_cool_tech,cool_tech_values,inside_cool_tech,giving_back,think_green,tech_support,discount-coupon'))){
//skip these pages
} else {

//...execute the code

}  

Thanks, Kim

25 Jan 2010, 5:44 PM
#76
kburner avatar

kburner

Totally Zenned

Join Date:
Apr 2008
Location:
Flint, Michigan
Posts:
684
Plugin Contributions:
0

Re: Show/Hide sideboxes based on page

kburner:

I am somewhat confused with coding as I go through this thread.

My goal is to hide certain sideboxes from the product pages. But, do not see sideboxes files for them. Sideboxes to hide: newsletter, links, testimonials, and About Us.

Which file? I think this may be code? Where should it go in file at?

if (in_array($current_page_base, explode(',','about_cool_tech,cool_tech_values,inside_cool_tech,giving_back,think_green,tech_support,discount-coupon'))){
//skip these pages
} else {

//...execute the code

}

> 
> Thanks, Kim

Anyone?
26 Jan 2010, 8:34 PM
#77
kburner avatar

kburner

Totally Zenned

Join Date:
Apr 2008
Location:
Flint, Michigan
Posts:
684
Plugin Contributions:
0

Re: Show/Hide sideboxes based on page

I want to hide certain sideboxes from product pages or basically keep only on main page. I went to includes/template/my temp/common/tpl_main_page. I added this code to keep only on main page for links side box, newsletter side box(subscribe), testimonials side box and About Us (ezpages).

$main_page_only = array('testimonials-manager','subscribe','linksbox','ezpages');
if (in_array($current_page_base,$main_page_only) ) {
$flag_disable_right = true;
$flag_disable_left = true;
}

I still can not get it to work. :frusty::frusty:

28 Jan 2010, 8:01 AM
#78
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 you really want those sideboxes only on the home page, use```php
if (!$this_is_home_page){
$flag_disable_left = true;
$flag_disable_right = true;
}

or to target just those pages
```php
if (in_array($current_page_base, explode(',','testimonials-manager,subscribe,linksbox,ezpages'))){
  $flag_disable_left = true;
  $flag_disable_right = true;
}
```I know this should be equivalent to the test you posted, but I have successfully used this version many times.
28 Jan 2010, 2:41 PM
#79
kburner avatar

kburner

Totally Zenned

Join Date:
Apr 2008
Location:
Flint, Michigan
Posts:
684
Plugin Contributions:
0

Re: Show/Hide sideboxes based on page

gjh42:

If you really want those sideboxes only on the home page, use```php
if (!$this_is_home_page){
$flag_disable_left = true;
$flag_disable_right = true;
}

> or to target just those pages
> ```php
if (in_array($current_page_base, explode(',','testimonials-manager,subscribe,linksbox,ezpages'))){
  $flag_disable_left = true;
  $flag_disable_right = true;
}
```I know this should be equivalent to the test you posted, but I have successfully used this version many times.

I do not know what I am doing wrong. I put it as the top of the page in includes/template/my temp/common/tpl_main_page....I will work on it some more..
28 Jan 2010, 2:44 PM
#80
ajeh avatar

ajeh

Oba-san

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

Re: Show/Hide sideboxes based on page

Just curious ... are you trying to turn off individual sideboxes or are you trying to turn off columns? :unsure:

These variables and their values:
$flag_disable_left = true;
$flag_disable_right = true;

are used to control the left and right columns ... and, when placed correctly in the code the whole column will turn off ...

If you want to turn off individual sideboxes, look at how the featured.php sidebox module is written where you see:

// test if box should display
  $show_featured= true;

  if ($show_featured == true) {

currently, nothing "controls" or changes that sidebox but the code is there so that you "could" change when this shows such as only show the sidebox when on the main page:

// test if box should display
  $show_featured= true;

if (!$this_is_home_page) {
  $show_featured= false;
}
  if ($show_featured == true) {

Notice on this sidebox how the IF statement surrounds the whole code ...

Any sidebox where this type of IF does not exist, you can set it up yourself to have similar logic ...