• Resolved jjrocket

    (@jjrocket)


    I want to add a custom search form within a custom sidebar. For some reason the form code does not show up when I add it to sidebar-custom.php. The form code does show up when I add it to page.php or some other file. It’s probably a simple php thing.

    Here is my custom search form, very standard code:

    <form id="searchform" action="<?php bloginfo('url'); ?>/" method="get">
    <input class="inlineSearch" type="text" name="s" value="Enter a keyword" onblur="if (this.value == '') {this.value = 'Enter a keyword';}" onfocus="if (this.value == 'Enter a keyword') {this.value = '';}" />
    <input type="hidden" name="post_type" value="portfolio" />
    <input class="inlineSubmit" id="searchsubmit" type="submit" alt="Search" value="Search" />
    </form>

    Here is my sidebar-custom.php, just like regular sidebar stuff:

    <?php
    
    if ( is_active_sidebar( 'inv-sb' ) ) : ?>
    	<aside id="secondary" class="sidebar-container" role="complementary">
    		<div class="sidebar-inner">
    			<div class="widget-area">
                               <?php dynamic_sidebar( 'inv-sb' ); ?>
    			</div>
    		</div>
    	</aside><!-- #secondary -->
    <?php endif; ?>

    I’ve tried adding the form code in a few different spots in the sidebar-custom.php without getting it to work. This doesn’t work:

    <?php
    
    if ( is_active_sidebar( 'inv-sb' ) ) : ?>
    	<aside id="secondary" class="sidebar-container" role="complementary">
    		<div class="sidebar-inner">
    			<div class="widget-area">
    <form id="searchform" action="<?php bloginfo('url'); ?>/" method="get">
    <input class="inlineSearch" type="text" name="s" value="Enter a keyword" onblur="if (this.value == '') {this.value = 'Enter a keyword';}" onfocus="if (this.value == 'Enter a keyword') {this.value = '';}" />
    <input type="hidden" name="post_type" value="portfolio" />
    <input class="inlineSubmit" id="searchsubmit" type="submit" alt="Search" value="Search" />
    </form>
                               <?php dynamic_sidebar( 'inv-sb' ); ?>
    			</div>
    		</div>
    	</aside><!-- #secondary -->
    <?php endif; ?>

    I want that custom form code to appear within the sidebar-inner div.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Your code tests fine on my installation. Do you see any errors in your server logs? Are you calling in your custom sidebar template correctly? If your file name is sidebar-custom.php, then you need to call get_sidebar( 'custom' ); or WordPress won’t load the right file.

    Thread Starter jjrocket

    (@jjrocket)

    That was the problem – it works now! Thank you.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Adding form code to sidebar.php’ is closed to new replies.