Support » Developing with WordPress » identifying search results page

  • Resolved SaladGoat

    (@saladgoat)


    I have two sidebars – one is default and the other is called on certain pages, to replace the default. This is done in sidebar.php

    Specifically:

    <?php if ( is_active_sidebar( 'sidebar-1' ) && ! is_page_template( 'page_writings-template.php' ) ) : ?>
    	<aside id="secondary" class="sidebar widget-area" role="complementary">
    		<?php dynamic_sidebar( 'sidebar-1' ); ?>
    	</aside><!-- .sidebar .widget-area -->
    <?php endif; ?>
    
    <?php if ( is_active_sidebar( 'sidebar-4' ) && is_page_template( 'page_writings-template.php' ) ) : ?>
    	<aside id="writings" class="sidebar widget-area" role="complementary">
    		<?php dynamic_sidebar( 'sidebar-4' ); ?>
    	</aside><!-- .sidebar .widget-area -->
    <?php endif; ?>
    

    Now I need the second (non-default) sidebar to show up on the search results page, but I have no idea how to do it. Adding || is_search() to the second block does not work and now I’m out of ideas. lol

    Googling only gets me a bunch of ‘how to configure your search page’ or ‘how to make your site show up in Google searches’.

    Please help?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi @saladgoat. is_search() should do the trick. Does this work?

    <?php if ( is_active_sidebar( 'sidebar-1' ) && ! ( is_page_template( 'page_writings-template.php' ) || is_search() ) ) : ?>
    	<aside id="secondary" class="sidebar widget-area" role="complementary">
    		<?php dynamic_sidebar( 'sidebar-1' ); ?>
    	</aside><!-- .sidebar .widget-area -->
    <?php endif; ?>
    
    <?php if ( is_active_sidebar( 'sidebar-4' ) && ( is_page_template( 'page_writings-template.php' ) || is_search() ) ) : ?>
    	<aside id="writings" class="sidebar widget-area" role="complementary">
    		<?php dynamic_sidebar( 'sidebar-4' ); ?>
    	</aside><!-- .sidebar .widget-area -->
    <?php endif; ?>
    
    Thread Starter SaladGoat

    (@saladgoat)

    Hi @noisysocks – no that doesn’t work, but it opened a pathway in my brain to show me what I was missing. Changing the || to &&! in the first block did the trick. I hadn’t been looking at the first block at all (when editing the code) and it turned out that the second sidebar was rendering below the first one. They are both very long and I wasn’t scrolling down far enough to realize my mistake.

    Thanks for helping!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘identifying search results page’ is closed to new replies.