Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

If I wanted to show a slider on the home page only, is it better or does it make a difference if I:

  • use a PHP if/then statement and echo a division and markup, or
  • use CSS along with a body class and display none the division? or
  • a combination of both

What's the best practice?

share|improve this question
    
Conditional Tags is Good Option –  Mohit Bumb Oct 3 '11 at 13:09

2 Answers 2

up vote 1 down vote accepted

target homepage only with if statement.

if ( is_front_page() or is_home() )

}

if your home page has page/2 page/3 then use the following to display the slider on only page 1 of the homepage.

if ( is_front_page() or is_home() && ! is_paged() ) {

}
share|improve this answer
    
Important to note, that I used or for a reason. It's more lightweight than || and && so the first one will be checked first and than compared to the result or ! is_paged(). –  kaiser Aug 30 '12 at 12:51
if ( is_front_page() or is_home() )
{
    // Your Slider Code
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.