Jump to content

how can i display a div if the page is homepage, search page or single page of wordpress theme.


adamsevera

Recommended Posts

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 :P

<?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 } ?>

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 } ?>

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.