Forums / Templates, Stylesheets, Page Layout / Hide a <div> in JUST the home page..

Hide a <div> in JUST the home page..

Views: 4,550

Results 1 to 20 of 30
26 Sep 2014, 7:53 PM
#1
divavocals avatar

divavocals

Totally Zenned

Join Date:
Jan 2007
Location:
Los Angeles, California, United States
Posts:
10,011
Plugin Contributions:
3

Hide a <div> in JUST the home page..

So I'm trying this code to hide a <div> on JUST on the home page:

<?php    
if ($this_is_home_page) {
echo "<style>#ez-feature-top-container-wrap {display: none;}</style>";
} 
?>

To my dismay it works on EVERY page.. What did I miss/do wrong here??? :frusty:

My Site - Zen Cart & WordPress integration specialist
I don't answer support questions via PM. Post add-on support questions in the support thread. The question & the answer will benefit others with similar issues.

26 Sep 2014, 8:32 PM
#2
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,119
Plugin Contributions:
56

Re: Hide a <div> in JUST the home page..

The code itself looks OK, but where are you using that? In a template file (should work)? In a function (it'll need a global $this_is_home_page; definition). Is it in an initialization file where the variable has not yet been set?

26 Sep 2014, 9:35 PM
#3
divavocals avatar

divavocals

Totally Zenned

Join Date:
Jan 2007
Location:
Los Angeles, California, United States
Posts:
10,011
Plugin Contributions:
3

Re: Hide a <div> in JUST the home page..

lat9:

The code itself looks OK, but where are you using that? In a template file (should work)? In a function (it'll need a global $this_is_home_page; definition). Is it in an initialization file where the variable has not yet been set?

I'm using it in a template file:
includes/templates/YOUR_TEMPLATE/common/tpl_main_page.php

Using this code later on the page to show the slideshow on the home page and it works fine

<?php    
if ($this_is_home_page) {
echo do_shortcode("[huge_it_slider id='1']");
} 
?>

My Site - Zen Cart & WordPress integration specialist
I don't answer support questions via PM. Post add-on support questions in the support thread. The question & the answer will benefit others with similar issues.

26 Sep 2014, 10:12 PM
#4
barco57 avatar

barco57

Totally Zenned

Join Date:
Apr 2006
Location:
West Salem, IL
Posts:
2,846
Plugin Contributions:
0

Re: Hide a <div> in JUST the home page..

have you tried dropping this into the bottom of the stylesheet?

#indexHomeBody #ez-feature-top-container-wrap {display:none}

that or something like that should work as the only place #indexHomeBody exists is the homepage

Mike
AEIIA - Zen Cart Certified & PCI Compliant Hosting
The Zen Cart Forum...Better than a monitor covered with post-it notes!

26 Sep 2014, 11:29 PM
#5
divavocals avatar

divavocals

Totally Zenned

Join Date:
Jan 2007
Location:
Los Angeles, California, United States
Posts:
10,011
Plugin Contributions:
3

Re: Hide a <div> in JUST the home page..

barco57:

have you tried dropping this into the bottom of the stylesheet?

#indexHomeBody #ez-feature-top-container-wrap {display:none}

> that or something like that should work as the only place #indexHomeBody exists is the homepage

Except I WANT this code to display on the home page, but nowhere else...

My Site - Zen Cart & WordPress integration specialist
I don't answer support questions via PM. Post add-on support questions in the support thread. The question & the answer will benefit others with similar issues.

26 Sep 2014, 11:58 PM
#7
barco57 avatar

barco57

Totally Zenned

Join Date:
Apr 2006
Location:
West Salem, IL
Posts:
2,846
Plugin Contributions:
0

Re: Hide a <div> in JUST the home page..

I'm confused.....

So I'm trying this code to hide a <div> on JUST on the home page
So you want to hide #ez-feature-top-container-wrap on the homepage only according to the first post right?

Mike
AEIIA - Zen Cart Certified & PCI Compliant Hosting
The Zen Cart Forum...Better than a monitor covered with post-it notes!

27 Sep 2014, 12:03 AM
#8
divavocals avatar

divavocals

Totally Zenned

Join Date:
Jan 2007
Location:
Los Angeles, California, United States
Posts:
10,011
Plugin Contributions:
3

Re: Hide a <div> in JUST the home page..

picaflor-azul:

use the same thing but with display:block !important;

Thanks,

Anne

If this is what you meant, this didn't work either..

<?php    
if ($this_is_home_page) {
echo "<style>#ez-feature-top-container-wrap {display:block !important;}</style>";
} 
?>

The code now displays on all pages.. I only want to display it on the home page..

My Site - Zen Cart & WordPress integration specialist
I don't answer support questions via PM. Post add-on support questions in the support thread. The question & the answer will benefit others with similar issues.

27 Sep 2014, 12:38 AM
#9
picaflor_azul avatar

picaflor_azul

Totally Zenned

Join Date:
Jul 2009
Location:
picaflor-azul.com
Posts:
6,940
Plugin Contributions:
28

Re: Hide a <div> in JUST the home page..

DivaVocals:

If this is what you meant, this didn't work either..

<?php if ($this_is_home_page) { echo "<style>#ez-feature-top-container-wrap {display:block !important;}</style>"; } ?>
> 
> The code now displays on all pages.. I only want to display it on the home page..

No, I meant to add the code to the stylesheet

Thanks,

Anne
27 Sep 2014, 6:03 AM
#10
rbarbour avatar

rbarbour

Totally Zenned

Join Date:
Feb 2010
Posts:
2,159
Plugin Contributions:
10

Re: Hide a <div> in JUST the home page..

I tried this in tpl_main_page.php

<?php if ($this_is_home_page) { echo "<style>div#logoWrapper {display: none;}</style>"; } ?>

Completely hides the Logo Wrapper on home page only.

<?php if ($this_is_home_page) { echo "<style>div#logoWrapper {visibility: hidden;}</style>"; } ?>

Also works removing the logo but maintaining the space

27 Sep 2014, 9:35 AM
#11
rodg avatar

rodg

Deceased

Join Date:
Jan 2007
Location:
Australia
Posts:
6,263
Plugin Contributions:
4

Re: Hide a <div> in JUST the home page..

DivaVocals:

So I'm trying this code to hide a <div> on JUST on the home page:

<?php if ($this_is_home_page) { echo "<style>#ez-feature-top-container-wrap {display: none;}</style>"; } ?>
> 
> To my dismay it works on EVERY page.. What did I miss/do wrong here??? :frusty:


I think the 1st thing to do would be to determine the value of  "$this_is_home_page" isn't somehow being set when NOT the home page.  

The other thing I might try would be to add an 'else' condition to the code so that it explicitly outputs something like 
echo "<style>#ez-feature-top-container-wrap {display: block;}</style>" if NOT the home page.  

Cheers
RodG

NOTE: We are sorry that Rod is no longer with us.
We are grateful for all his contributions to the Zen Cart community.

Ozpost - The Ultimate Shipping module for Australian Merchants. Click these links for its Homepage, or Download from Zen-Cart.com.

27 Sep 2014, 1:50 PM
#12
divavocals avatar

divavocals

Totally Zenned

Join Date:
Jan 2007
Location:
Los Angeles, California, United States
Posts:
10,011
Plugin Contributions:
3

Re: Hide a <div> in JUST the home page..

barco57:

I'm confused.....

So you want to hide #ez-feature-top-container-wrap on the homepage only according to the first post right?

Sorry mistated in OP.. wanna DISPLAY it.. JUST on the home page..

My Site - Zen Cart & WordPress integration specialist
I don't answer support questions via PM. Post add-on support questions in the support thread. The question & the answer will benefit others with similar issues.

27 Sep 2014, 2:02 PM
#13
divavocals avatar

divavocals

Totally Zenned

Join Date:
Jan 2007
Location:
Los Angeles, California, United States
Posts:
10,011
Plugin Contributions:
3

Re: Hide a <div> in JUST the home page..

RodG:

I think the 1st thing to do would be to determine the value of "$this_is_home_page" isn't somehow being set when NOT the home page.Right.. except as I indicted earlier I am also using the $this_is_home_page on the same page to display the slideshow ONLY on the home page and that code works just fine..

RodG:

The other thing I might try would be to add an 'else' condition to the code so that it explicitly outputs something like
echo "<style>#ez-feature-top-container-wrap {display: block;}</style>" if NOT the home page.

Good morning.. Looks like we had the same idea Rod.. After thinking about this overnight I too realized that this was the answer.. So I changed my code as follows:

<?php    
    if ($this_is_home_page) {
        echo "<style>#ez-feature-top-container-wrap {display:block !important;}</style>";
            } else {
        echo "<style>#ez-feature-top-container-wrap {display:none;}</style>";
    }
?>

Now the container displays on the home page ONLY. Thanks everyone for the tips and pointers.. Put it all together and it got me moving in the right direction.. Gotta love the Zen Cart community!!

My Site - Zen Cart & WordPress integration specialist
I don't answer support questions via PM. Post add-on support questions in the support thread. The question & the answer will benefit others with similar issues.

28 Sep 2014, 4:59 PM
#14
rodg avatar

rodg

Deceased

Join Date:
Jan 2007
Location:
Australia
Posts:
6,263
Plugin Contributions:
4

Re: Hide a <div> in JUST the home page..

DivaVocals:

Good morning.. Looks like we had the same idea Rod.. After thinking about this overnight I too realized that this was the answer..

If this a case of great minds thinking alike, or fools never differ? <g>

Hmmm. Better not answer that...

Cheers
RodG

NOTE: We are sorry that Rod is no longer with us.
We are grateful for all his contributions to the Zen Cart community.

Ozpost - The Ultimate Shipping module for Australian Merchants. Click these links for its Homepage, or Download from Zen-Cart.com.

28 Sep 2014, 5:59 PM
#15
divavocals avatar

divavocals

Totally Zenned

Join Date:
Jan 2007
Location:
Los Angeles, California, United States
Posts:
10,011
Plugin Contributions:
3

Re: Hide a <div> in JUST the home page..

RodG:

If this a case of great minds thinking alike, or fools never differ? <g>

Hmmm. Better not answer that...

Cheers
RodG

:laugh: I'll go with the former..

My Site - Zen Cart & WordPress integration specialist
I don't answer support questions via PM. Post add-on support questions in the support thread. The question & the answer will benefit others with similar issues.

29 Sep 2014, 12:43 AM
#16
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Hide a <div> in JUST the home page..

I'm cuious why all the extra coding rather than using the appropriate css stylesheet for the div tag to be shown when on the index page and hidden at all other times?

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

29 Sep 2014, 1:17 AM
#17
divavocals avatar

divavocals

Totally Zenned

Join Date:
Jan 2007
Location:
Los Angeles, California, United States
Posts:
10,011
Plugin Contributions:
3

Re: Hide a <div> in JUST the home page..

mc12345678:

I'm cuious why all the extra coding rather than using the appropriate css stylesheet for the div tag to be shown when on the index page and hidden at all other times?

Because I can't use the page specific stylesheets to NOT display the container on ALL pages EXCEPT the home unless I'm willing to create a GAZILLION page specific stylesheets whose only purpose would be to support not displaying this one container.. and I did NOT want to create a bunch of stylesheets just to support NOT displaying this one div..

Happy to be proven wrong if you have a solution that doesn't require me to create a GAZILLION stylsheets to simply NOT display this container on the rest of the site..

Remember I want it to DISPLAY on the homepage and NOT on the rest of the site..

My Site - Zen Cart & WordPress integration specialist
I don't answer support questions via PM. Post add-on support questions in the support thread. The question & the answer will benefit others with similar issues.

29 Sep 2014, 2:06 AM
#18
rbarbour avatar

rbarbour

Totally Zenned

Join Date:
Feb 2010
Posts:
2,159
Plugin Contributions:
10

Re: Hide a <div> in JUST the home page..

Why not just wrap the entire container in the if statement, no need for CSS

<?php if ($this_is_home_page) { echo '<div id="ez-feature-top-container-wrap">'; echo 'Content of Container'; echo '</div>'; } else { echo ''; } ?>
29 Sep 2014, 5:59 AM
#19
divavocals avatar

divavocals

Totally Zenned

Join Date:
Jan 2007
Location:
Los Angeles, California, United States
Posts:
10,011
Plugin Contributions:
3

Re: Hide a <div> in JUST the home page..

rbarbour:

Why not just wrap the entire container in the if statement, no need for CSS

<?php if ($this_is_home_page) { echo '<div id="ez-feature-top-container-wrap">'; echo 'Content of Container'; echo '</div>'; } else { echo ''; } ?>

The code is coming from WordPress.. Hence why I HAVE to use the CSS to hide this container.. I could hire a developer to write a bunch of code to do this with code and no CSS.. This was a simpler solution.. and it works so I don't see the downside here.. Happy to be proven wrong though..:smile:

My Site - Zen Cart & WordPress integration specialist
I don't answer support questions via PM. Post add-on support questions in the support thread. The question & the answer will benefit others with similar issues.

29 Sep 2014, 6:22 AM
#20
rbarbour avatar

rbarbour

Totally Zenned

Join Date:
Feb 2010
Posts:
2,159
Plugin Contributions:
10

Re: Hide a <div> in JUST the home page..

Not my intentions, I also agree that their is no downside, just giving alternatives and suggestions. :P

DivaVocals:

The code is coming from WordPress.. Hence why I HAVE to use the CSS to hide this container.. I could hire a developer to write a bunch of code to do this with code and no CSS.. This was a simpler solution.. and it works so I don't see the downside here.. Happy to be proven wrong though..:smile: