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 21 to 30 of 30
29 Sep 2014, 7:02 AM
#21
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..

rbarbour:

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

I appreciate the insight as always.. For the record I tried a BUNCH of other code based solutions and had only partial success.. I may eventually go back to one of them at some later point and try to work out the kinks.. but that day ain't today!! :laugh:

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, 4:03 PM
#22
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..

rbarbour:

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

Before I comment further, I will state that there is no 'right' or 'wrong' way of achieving the desired results, but personally I tend towards using CSS for this kind of thing rather than code. I find it helps separate function from content.

Having said that, in a case like this (without having a stylesheet for each page) there is always going to be some code required anyway.

Although my original suggestion to DivaVocals was along the lines of the solution taken, in reality I probably would have opted for a slightly different method.

<?php 
$style = "display:none";  
    if ($this_is_home_page) {
       $style = "display:block !important" ;
     } 


echo "<style>#ez-feature-top-container-wrap {$style;}</style>";
?> 

The benefit of using this method over the solution taken is that the $style variable can be initialised at the top of the page, with the actual echo/output located deeper in the code where it is actually needed/used.

Nah... I just changed my mind again :)

Something like

 $useClass = "ez-feature-top-container-wrap hidden" ;

 if ($this_is_home_page) {
$useClass = "ez-feature-top-container-wrap" ;
} 


echo "<div class=$useClass>" ;


... stuff goes here ..


echo "</div>" ; 

Then in my stylesheet.css

.ez-feature-top-container-wrap {
display: block ; 
}

.ez-feature-top-container-wrap hidden {
display: none ; 
}
 

The reason why I believe this is a better option (bearing in mind I've no real idea what is actually to be displayed) is that this allows additional control for mobile devices. For example, if the output happens to be a large banner that simply doesn't 'work' correctly on a mobile device, then another addition to the stylesheet along the lines of.................

@media (max-width: 320px) {  
 
  ez-feature-top-container-wrap {
 display: none ;
    }
}

.... can be used... The net result being the banner (or whatever) will only be displayed on the home page but only if the screen width is larger than 320px.

Pretty neat eh?

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.

29 Sep 2014, 5:44 PM
#23
mc12345678 avatar

mc12345678

Totally Zenned

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

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

Agree, no "right" way, also offerring solutions, so this is what I was referring.

Knowing that it would be a "mostly" off condition, the stylesheet.css would have the do not display css associated with the div tag, and only one specialized css sheet would be needed to unhide the div.

The index_home.css sheet would contain the css to unhide the div. In the sequence of loading the stylesheet.css would load first with the hide property in all cases. When the home page is the page loaded, then the index_home.css file content would be loaded and that css will override the stylesheet css. Tada not a million sheets, just two. The only code hack was to add the tag(s) to begin with...like Rod was getting at, then also have more control over when/how the content is shown

Used: http://www.zen-cart.com/wiki/index.php/Customisation_-_Templates_-_Stylesheets_-_Per-Page-Rules
As a reference.

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

29 Sep 2014, 6:23 PM
#24
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..

thanks everyone.. I'll take a look at those alternate solutions..

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.

30 Sep 2014, 4:57 AM
#25
dw08gm avatar

dw08gm

Totally Zenned

Join Date:
Sep 2008
Location:
DownUnder, overlooking South Pole.
Posts:
1,019
Plugin Contributions:
2

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

Very neat, thank you.

30 Sep 2014, 5:18 PM
#26
rbarbour avatar

rbarbour

Totally Zenned

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

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

RodG:

Before I comment further, I will state that there is no 'right' or 'wrong' way of achieving the desired results, but personally I tend towards using CSS for this kind of thing rather than code. I find it helps separate function from content.

Having said that, in a case like this (without having a stylesheet for each page) there is always going to be some code required anyway.

Although my original suggestion to DivaVocals was along the lines of the solution taken, in reality I probably would have opted for a slightly different method.

<?php $style = "display:none"; if ($this_is_home_page) { $style = "display:block !important" ; } echo "<style>#ez-feature-top-container-wrap {$style;}</style>"; ?>
> 
> The benefit of using this method over the solution taken is that the $style variable can be initialised at the top of the page, with the actual echo/output located deeper in the code where it is actually needed/used.  

For personal reasons I prefer not to add CSS declarations in CODE. :lookaroun

> **RodG:**
>
> Nah... I just changed my mind again  :)  
> 
> Something like 
> 
> ```
 $useClass = "ez-feature-top-container-wrap hidden" ;

 if ($this_is_home_page) {
$useClass = "ez-feature-top-container-wrap" ;
} 


echo "<div class=$useClass>" ;


... stuff goes here ..


echo "</div>" ; 

Then in my stylesheet.css

.ez-feature-top-container-wrap {
display: block ;
}

.ez-feature-top-container-wrap hidden {
display: none ;
}

> 
> The reason why I believe this is a better option (bearing in mind I've no real idea what is actually to be displayed) is that this allows additional control for mobile devices.   For example,  if the output happens to be a large banner that simply doesn't 'work' correctly on a mobile device, then another addition to the stylesheet along the lines of................. 
> 
> ```
@media (max-width: 320px) {  
 
  ez-feature-top-container-wrap {
 display: none ;
    }
}

.... can be used... The net result being the banner (or whatever) will only be displayed on the home page but only if the screen width is larger than 320px.

I use a very similar CODE and CSS in my responsive templates to hide/show the side-boxes.

RodG:

Pretty neat eh?

Cheers
RodG

Yep, pretty neat! :smile:

30 Sep 2014, 5:47 PM
#27
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..

rbarbour:

For personal reasons I prefer not to add CSS declarations in CODE. :lookaroun

Same here (which is why I changed my mind about using that method). Doing so pretty much defeats the purpose of .css.

It comes in handy for 'quick n dirty' testing/development though (sometimes). For me, it much depends whether I'm using an IDE or a text editor on a live site. ;-)

I also have no qualms in using it when trying to help others using their own code snippets.... before offering/suggesting more advanced/better methods.

Like I said at the outset, I don't consider any particular way of doing things as being 'right' or 'wrong' (I figure, as long as it works, its 'right', and if it doesn't work, it's 'wrong'). LOL

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.

30 Sep 2014, 5:54 PM
#28
rbarbour avatar

rbarbour

Totally Zenned

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

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

RodG:

Like I said at the outset, I don't consider any particular way of doing things as being 'right' or 'wrong' (I figure, as long as it works, its 'right', and if it doesn't work, it's 'wrong'). LOL

Cheers
RodG

LMAO :laugh: - couldn't have put it better!

30 Sep 2014, 6:40 PM
#29
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:

Something like

$useClass = "ez-feature-top-container-wrap hidden" ;

if ($this_is_home_page) {
$useClass = "ez-feature-top-container-wrap" ;
}

echo "<div class=$useClass>" ;

... stuff goes here ..

echo "</div>" ;

> 
> Then in my stylesheet.css 
> 
> ```
.ez-feature-top-container-wrap {
display: block ; 
}

.ez-feature-top-container-wrap hidden {
display: none ; 
}
 

Gonna give this a looksee, but I'm not entirely sure that this will work for my particular situation.. Not sure that the index_home.css suggestion is THAT much different that the solution I have working now..

Long term though, I have been brainstorming approaching this from a different angle. Gonna explore some other options within my WordPress theme framework to improve the Zen Cart/WordPress theme integration I am after.. The container I am trying to suppress comes from a special widget that is part of the theme framework and it is not possible to call this widget on it's own.. So instead of using it, I am looking at creating a custom widget and shortcode for this custom widget. Then I can wrap the shortcode PHP inside the "$this_is_home_page" condition..

But that is long term.... Meanwhile gonna stick with my short term solution..

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.

30 Sep 2014, 6:42 PM
#30
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:

Like I said at the outset, I don't consider any particular way of doing things as being 'right' or 'wrong' (I figure, as long as it works, its 'right', and if it doesn't work, it's 'wrong'). LOL
Yep.. for now the solution in place is achieving my IMMEDIATE objective.. But I appreciate the suggestions from everyone.. Ya'll have FORCED me to look at a longer term solution NOW!!!:laugh: Which I would have done anyway because IMHO my current solution is a bandaid.. I'm not a fan of leaving bandaids in place long term..

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.