T.Doe T.Doe - 7 months ago 10
PHP Question

How do I get a navbar to only show on the product category page?

I have a navbar that I only want to appear on the product category page on my woocommerce site. Does anybody know what php or javascript code I need to make this happen? Thanks in advance!

HTML of the navbar (currently in the index.php file)

<nav class="navbar navbar-inverse" data-spy="affix" data-offset-top="91" id="search-nav"></nav>


Note: I'm using Wordpress, Woocommerce and Twitter Bootstrap

Answer

WooCommerce provides the is_product_category() conditional to check if the user is viewing a product category archive page:

<?php if( is_product_category() ): ?>

    <nav class="navbar navbar-inverse" data-spy="affix" data-offset-top="91" id="search-nav"></nav>

<?php endif; ?>