js111
js111

Reputation: 1314

PHP hide div on specific pages?

My site is located here: http://math.pixelworklab.com/home-study

I am looking to hide the navigation bar only on two pages

Checkout

Cart

Basically prevent the user from being distracted with other links while checking out.

How would I hide this div on these pages using an IF statement?

UPDATE:

/* Navigation */

if ( ! function_exists( 'woo_nav' ) ) {
    function woo_nav() { 
        global $woo_options;
        woo_nav_before();
?>

<?php if (strpos($_SERVER['REQUEST_URI'],'/checkout/') === false 
       || strpos($_SERVER['REQUEST_URI'],'/cart/') === false ):?>

    <div id="navigation" class="col-full">
        <?php woo_nav_inside(); ?>
        <?php
        if ( function_exists( 'has_nav_menu' ) && has_nav_menu( 'primary-menu' ) ) {
            wp_nav_menu( array( 'sort_column' => 'menu_order', 'container' => 'ul', 'menu_id' => 'main-nav', 'menu_class' => 'nav fl', 'theme_location' => 'primary-menu' ) );
        } else {
        ?>
        <ul id="main-nav" class="nav fl">
            <?php 
            if ( get_option( 'woo_custom_nav_menu' ) == 'true' ) {
                if ( function_exists( 'woo_custom_navigation_output' ) )
                    woo_custom_navigation_output( "name=Woo Menu 1" );

            } else { ?>

                <?php if ( is_page() ) $highlight = "page_item"; else $highlight = "page_item current_page_item"; ?>
                <li class="<?php echo $highlight; ?>"><a href="<?php echo home_url( '/' ); ?>"><?php _e( 'Home', 'woothemes' ); ?></a></li>
                <?php wp_list_pages( 'sort_column=menu_order&depth=6&title_li=&exclude=' ); ?>
            <?php } ?>
        </ul><!-- /#nav -->
        <?php } ?>  

        <?php endif;?>
    </div><!-- /#navigation -->
<?php
        woo_nav_after();
    } // End woo_nav()
}

Upvotes: 5

Views: 4975

Answers (5)

user2417509
user2417509

Reputation: 1

I think that @Grzegorz gave a very simple and elegant solution !

In any case you can use double class div :

<div class="to_be_seen invisible">Bla bla blah...</div> 

with the code of what you want to be seen/hidden and a call for the CSS into specific pages template :

<style>
.to_be_seen {color:red;...}
.invisible {display:none;}
</style>

Upvotes: 0

Libin
Libin

Reputation: 2462

You can use the Conditional Tag is page

This checks if the Pages are being displayed or not. Wrap your navigation menu code inside the else condition.

<?php
if(is_page(array(42,43))) {
// Returns true when the Pages displayed is either page ID 42 or 43. Change it to the page id of cart and checkout.

} else {

<div ... navigation ...</div>

}
?>

Hope this will help you. Cheers!!!

Upvotes: 1

Ibu
Ibu

Reputation: 43830

How about you only display the navigation if it is not those pages:

<?php if (strpos($_SERVER['REQUEST_URI'],'/checkout/') === false 
       || strpos($_SERVER['REQUEST_URI'],'/cart/') === false ):?>
<div ... navigation ...</div>
<?php endif;?>

Upvotes: 4

Grzegorz
Grzegorz

Reputation: 3335

Can you use different css files for these pages? If you can then add a class into your div, let's say optional_hide, and add into css file for these two files:

div.optional_hide {display:none;}

For the rest pages this line can be missing.

Upvotes: 0

Alexei
Alexei

Reputation: 672

Well, I guess you could do something like:

<?php if (!in_array($post->ID, array(id_of_checkout_page, id_of_cart_page)) { ?>
    <div>...</div>
<?php } ?>

Upvotes: 0

Related Questions