ThemeShaper Forums » Thematic

[closed]

Add search bar to thematic using override

(9 posts)
  • Started 3 years ago by em hr
  • Latest reply from nimmolo
  • This topic is not a support question
  1. As an update to this awesome tutorial at cozmoslabs:

    http://www.cozmoslabs.com/2009/04/15/add-a-search-box-to-the-thematic-menu/

    Changes to 0.9.7.6 broke this great tut here is a method using a childtheme override so you can omit the remove action function mentioned in the tutorial

    function childtheme_override_access() { ?>
            <div id="access">
                <div class="skip-link"><a href="#content" title="<?php _e('Skip navigation to the content', 'thematic'); ?>"><?php _e('Skip to content', 'thematic'); ?></a></div>
    			<?php
    	    		if ((function_exists("has_nav_menu")) && (has_nav_menu(apply_filters('thematic_primary_menu_id', 'primary-menu')))) {
    	    			echo  wp_nav_menu(thematic_nav_menu_args());
        			} else {
        				echo  thematic_add_menuclass(wp_page_menu(thematic_page_menu_args()));
        			}
    	    	?>
                <div id="access-search">
                    <form id="searchform" method="get" action="<?php bloginfo('home') ?>">
                        <div>
                            <input id="s" name="s" type="text" value="<?php echo wp_specialchars(stripslashes($_GET['s']), true) ?>" size="20" tabindex="1" />
                            <input id="searchsubmit" name="searchsubmit" type="submit" value="<?php _e('Search', 'thematic') ?>" tabindex="2" />
                        </div>
                    </form>
                </div>
    
            </div><!-- #access -->
    <?php }

    -Gene

    Posted 3 years ago #
  2. krackpot
    Member

    Thanks for posting this. I think this is much easier than unhooking and adding back a new function. Looking at the function childtheme_override_access(), I'm able to understand that conditional statement in the thematic code.

    One issue I have with it is an error in the search box (This text appears in the box).

    <b>Notice</b>:  Undefined index: s in <b>D:\xampp2\htdocs\site\wp-content\themes\site\functions.php</b> on line <b>241</b>

    Which points to:

    <input id="s" name="s" type="text" value="<?php echo wp_specialchars(stripslashes($_GET['s']), true) ?>" size="20" tabindex="1" />

    being the culprit.

    Also, how do we get a search button to this method?

    I am using this code block in place of the one that gives error, but the search results seem incomplete (say I'm searching for a category, it says Nothing Found).

    <div id="access-search">
    				<form id="searchform" method="get" action="<?php bloginfo('home') ?>">
    					<fieldset class="search">
    						<input type="text" tabindex="1" size="20" name="s" id="s" />
    						<button class="btn" id="searchsubmit" name="searchsubmit" type="submit" value="SEARCH" tabindex="2">SEARCH</button>
    					</fieldset>
    				</form>
    			</div>

    Thanks again :)

    Posted 3 years ago #
  3. ok a perfectionist. i can appreciate that.

    try this:

    function childtheme_override_access() { ?>
    
    	<?php
    
    	$search_dirty = ( isset($_GET['s']) ) ? $_GET['s'] : '';
    	$search = esc_html(stripslashes($search_dirty), true);
    
    	?>
    
            <div id="access">
                <div class="skip-link"><a href="#content" title="<?php _e('Skip navigation to the content', 'thematic'); ?>"><?php _e('Skip to content', 'thematic'); ?></a></div>
    			<?php
    	    		if ((function_exists("has_nav_menu")) && (has_nav_menu(apply_filters('thematic_primary_menu_id', 'primary-menu')))) {
    	    			echo  wp_nav_menu(thematic_nav_menu_args());
        			} else {
        				echo  thematic_add_menuclass(wp_page_menu(thematic_page_menu_args()));
        			}
    	    	?>
                <div id="access-search">
                    <form id="searchform" method="get" action="<?php bloginfo('url') ?>">
                        <div>
                            <input id="s" name="s" type="text" value="<?php echo $search ?>" size="20" tabindex="1" />
                            <input id="searchsubmit" name="searchsubmit" type="submit" value="<?php _e('Search', 'thematic') ?>" tabindex="2" />
                        </div>
                    </form>
                </div>
    
            </div><!-- #access -->
    <?php }

    That takes care of the notice, a deprecated function and a deprecated argument to bloginfo()

    Posted 3 years ago #
  4. krackpot
    Member

    Thanks so much! Works great! :)

    Posted 3 years ago #
  5. alonso
    Member

    Thank you this really helped me =)

    Posted 3 years ago #
  6. lushmind
    Member


    Posted 3 years ago #
  7. melomanda
    Member

    Hi here's a version using an image as a search button

    function childtheme_override_access() { ?>
    
    	<?php
    
    	$search_dirty = ( isset($_GET['s']) ) ? $_GET['s'] : '';
    	$search = esc_html(stripslashes($search_dirty), true);
    
    	?>
    
            <div id="access">
                <div class="skip-link"><a href="#content" title="<?php _e('Skip navigation to the content', 'thematic'); ?>"><?php _e('Skip to content', 'thematic'); ?></a></div>
    			<?php
    	    		if ((function_exists("has_nav_menu")) && (has_nav_menu(apply_filters('thematic_primary_menu_id', 'primary-menu')))) {
    	    			echo  wp_nav_menu(thematic_nav_menu_args());
        			} else {
        				echo  thematic_add_menuclass(wp_page_menu(thematic_page_menu_args()));
        			}
    	    	?>
                <div id="access-search">
                    <form id="searchform" method="get" action="<?php bloginfo('url') ?>">
                        <div>
                            <input id="s" name="s" type="text" value="<?php echo $search ?>" size="20" tabindex="1" />
                            <input id="searchsubmit" name="searchsubmit" type="image" src="<?php echo bloginfo('stylesheet_directory') ?>/images/YOUR-BUTTON-IMAGE.png" value="<?php _e('Search', 'thematic') ?>" tabindex="2" />
                        </div>
                    </form>
                </div>
    
            </div><!-- #access -->
    <?php }
    Posted 3 years ago #
  8. I know this post is six months old but thanks anyways. This was very helpful.

    Posted 2 years ago #
  9. nimmolo
    Member

    O M G thank you gene and melomanda

    Posted 2 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.