adamsevera Posted April 24, 2015 Share Posted April 24, 2015 I want to display a div if the page is homepage, search page or single page of wordpress theme. what would be the proper syntax for it? currently i am doing the following which i think is obviously the least ideal way to do this <?php if ( is_home()) { ?> <div class="container"> </div> <?php } ?> <?php if ( is_home()) { ?> <div class="container"> </div> <?php } ?> <?php if ( is_home()) { ?> <div class="container"> </div> <?php } ?> Link to comment https://forums.phpfreaks.com/topic/295813-how-can-i-display-a-div-if-the-page-is-homepage-search-page-or-single-page-of-wordpress-theme/ Share on other sites More sharing options...
adamsevera Posted April 24, 2015 Author Share Posted April 24, 2015 Oops sorry wrong code this is what i am currently using <?php if ( is_home()) { ?> <div class="container"> </div> <?php } ?> <?php if ( is_single()) { ?> <div class="container"> </div> <?php } ?> <?php if ( is_page()) { ?> <div class="container"> </div> <?php } ?> Link to comment https://forums.phpfreaks.com/topic/295813-how-can-i-display-a-div-if-the-page-is-homepage-search-page-or-single-page-of-wordpress-theme/#findComment-1509791 Share on other sites More sharing options...
maxxd Posted April 24, 2015 Share Posted April 24, 2015 You can shorten it a bit like so: <?php if( is_single() || is_home() || is_page() ): ?> <div class='container'></div> <?php endif; ?> Or you can just put the div in the template pages controlling those particular pages. I think (off the top of my head, so check the template hierarchy on the WordPress site), you'd be looking at index.php for the blog (home) page, single.php or page.php for the other two. I haven't had my second cup of coffee yet and just logged on at work, so I may be mistaken about which files you'll need to target. Link to comment https://forums.phpfreaks.com/topic/295813-how-can-i-display-a-div-if-the-page-is-homepage-search-page-or-single-page-of-wordpress-theme/#findComment-1509814 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.