ThemeShaper Forums » Thematic

[closed]

How to add a Google Search box above the header?

(7 posts)
  • Started 4 years ago by Polyglot
  • Latest reply from Polyglot
  • This topic is not resolved
  1. Hi,

    I would add a Google Search box above the header. I tried several methods found in the forum but I failed...

    This is the code of my function file:
    (I have already a widget area right to the title blog. I would to have another above the header)

    Thanks!

    <?php
    // This will create your widget area
    function my_widgets_init() {
        register_sidebar(array(
           	'name' => 'Header Aside',
           	'id' => 'header-aside',
           	'before_widget' => '<li id="%1$s" class="widgetcontainer %2$s">',
           	'after_widget' => "",
    		'before_title' => "<h3 class=\"widgettitle\">",
    		'after_title' => "</h3>\n",
        ));
    
    }
    add_action( 'init', 'my_widgets_init' );
    
    // adding the widget area to your child theme
    function my_header_widgets() {
    if ( function_exists('dynamic_sidebar') && is_sidebar_active('header-aside') ) {
        echo '<div id="header-aside" class="aside">'. "\n" . '<ul class="xoxo">' . "\n";
        dynamic_sidebar('header-aside');
        echo '' . "\n" . '</div><!-- #header-aside .aside -->'. "\n";
        echo "\n" . '</div><!-- #header-box -->'. "\n";
    }
    }
    add_action('thematic_header', 'my_header_widgets', 8);
    
    function remove_branding() {
    		remove_action('thematic_header','thematic_brandingopen',1);
    }
    add_action('init', 'remove_branding');
    
    function my_brandingopen() { ?>
    	<div id="header_box">
        	<div id="branding">
    <?php }
    add_action('thematic_header','my_brandingopen',1);
    
    ?>
    Posted 4 years ago #
  2. you don't need to make it a widget area unless you really, really need a widget. is your widget area the same name as the one you already have in the header?

    function google_search() {
    	$googlesearch = "Paste your search code here";
    
    	$googlesearch = "<div class='google-search'>" . $googlesearch . "</div>";
    		echo $googlesearch;
    }
    add_action('thematic_header', 'google_search', 1);
    
    function remove_brandingopen(){
             remove_action('thematic_header','thematic_brandingopen',1');
    }
    add_action('init','remove_brandingopen');
    
    add_action('thematic_header','thematic_brandingopen',2')
    Posted 4 years ago #
  3. Thanks for your reply.

    I think it's more simple if I give you the link to my blog (www.polyglot-abc.com)

    The widget area in my actual function file is those to the right.
    I'd to add the google search box above the title blog.

    I'm thinking to add another widget area because my blog is multilingual. I can add different search box in function of the selected language with WPML.

    I've added this code but it shows me a problem... Is it correct?

    <?php
    function google_search() {
    $googlesearch = "
    <form action="http://www.polyglot-abc.com/search-with-google/" id="cse-search-box">
    <div>
    <input type="hidden" name="cx" value="partner-pub-5039757846382224:w140gv-8n7x" />
    <input type="hidden" name="cof" value="FORID:11" />
    <input type="hidden" name="ie" value="UTF-8" />
    <input type="text" name="q" size="60" />
    <input type="submit" name="sa" value="Search" />
    </div>
    </form>
    <script type="text/javascript" src="http://www.google.com/cse/brand?form=cse-search-box&lang=en"></script>
    ";

    $googlesearch = "<div class='google-search'>" . $googlesearch . "</div>";
    echo $googlesearch;
    }
    add_action('thematic_header', 'google_search', 1);

    // This will create your widget area
    function my_widgets_init() {
    register_sidebar(array(
    'name' => 'Header Aside',
    'id' => 'header-aside',
    'before_widget' => '<li id="%1$s" class="widgetcontainer %2$s">',
    'after_widget' => "",
    'before_title' => "<h3 class=\"widgettitle\">",
    'after_title' => "</h3>\n",
    ));

    }
    add_action( 'init', 'my_widgets_init' );

    // adding the widget area to your child theme
    function my_header_widgets() {
    if ( function_exists('dynamic_sidebar') && is_sidebar_active('header-aside') ) {
    echo '<div id="header-aside" class="aside">'. "\n" . '<ul class="xoxo">' . "\n";
    dynamic_sidebar('header-aside');
    echo '' . "\n" . '</div><!-- #header-aside .aside -->'. "\n";
    echo "\n" . '</div><!-- #header-box -->'. "\n";
    }
    }
    add_action('thematic_header', 'my_header_widgets', 8);

    function remove_branding() {
    remove_action('thematic_header','thematic_brandingopen',1);
    }
    add_action('init', 'remove_branding');

    function my_brandingopen() { ?>
    <div id="header_box">
    <div id="branding">
    <?php }
    add_action('thematic_header','my_brandingopen',1);

    ?>

    Posted 4 years ago #
  4. Hi, the problem is still here...

    This is my code

    <?php
    function google_search() {
    $googlesearch = "
    <form action="http://www.polyglot-abc.com/search-with-google/" id="cse-search-box">
    <div>
    <input type="hidden" name="cx" value="partner-pub-5039757846382224:w140gv-8n7x" />
    <input type="hidden" name="cof" value="FORID:11" />
    <input type="hidden" name="ie" value="UTF-8" />
    <input type="text" name="q" size="60" />
    <input type="submit" name="sa" value="Search" />
    </div>
    </form>
    <script type="text/javascript" src="http://www.google.com/cse/brand?form=cse-search-box&lang=en"></script>
    ";

    $googlesearch = "<div class='google-search'>" . $googlesearch . "</div>";
    echo $googlesearch;
    }
    add_action('thematic_header', 'google_search', 1);

    // This will create your widget area
    function my_widgets_init() {
    register_sidebar(array(
    'name' => 'Header Aside',
    'id' => 'header-aside',
    'before_widget' => '<li id="%1$s" class="widgetcontainer %2$s">',
    'after_widget' => "",
    'before_title' => "<h3 class=\"widgettitle\">",
    'after_title' => "</h3>\n",
    ));

    }
    add_action( 'init', 'my_widgets_init' );

    // adding the widget area to your child theme
    function my_header_widgets() {
    if ( function_exists('dynamic_sidebar') && is_sidebar_active('header-aside') ) {
    echo '<div id="header-aside" class="aside">'. "\n" . '<ul class="xoxo">' . "\n";
    dynamic_sidebar('header-aside');
    echo '' . "\n" . '</div><!-- #header-aside .aside -->'. "\n";
    echo "\n" . '</div><!-- #header-box -->'. "\n";
    }
    }
    add_action('thematic_header', 'my_header_widgets', 8);

    function remove_branding() {
    remove_action('thematic_header','thematic_brandingopen',1);
    }
    add_action('init', 'remove_branding');

    function my_brandingopen() { ?>
    <div id="header_box">
    <div id="branding">
    <?php }
    add_action('thematic_header','my_brandingopen',1);

    ?>

    Do you have a suggestion?

    Thank you!

    Posted 4 years ago #
  5. well you should not be combining my code with your code. i suggested a way to add a search box without a widget. you are still trying to make a widget. i understand your reason for wanting a widget, so why not stick w/ that.

    the thing that jumps out at me immediately is <div id="header_box">. i'd get rid of it (all references to it) as i think (without testing or looking too closely) that you might not be closing divs in the right order.

    the code for adding the widget itself looks correct to me. what error are you getting? how are you failing? that helps us figure out what the problem is more than a vague "it doesn't work". ACTUALLY, now looking at your website's markup you clearly HAVE a header widget done correctly. can you just drop a search widget into that area?

    maybe this will help:
    http://wordpress.org/extend/plugins/google-custom-search-for-wordpress/

    sidenote- i would love to be a polyglot! je te souhaite plein de courage dans tes efforts à apprendre l'anglais. dans qqs aspects c'est plus facile (pas de masculine/feminine, pas de subjonctif) mais dans les autres c'est plus compliqué (les règles qui changent, etc).

    Posted 4 years ago #
  6. Hi,

    I found the code here:
    http://forums.themeshaper.com/topic/widgets-in-the-header

    I just found a new code here:
    http://forums.themeshaper.com/topic/something-new-bout-widgetized-areas#post-6660

    This is my new code in my function file:

    <?php
    function add_header_aside($content) {
    $content['Header Aside'] = array(
    'args' => array (
    'name' => 'Header Aside',
    'id' => 'header-aside',
    'before_widget' => thematic_before_widget(),
    'after_widget' => thematic_after_widget(),
    'before_title' => thematic_before_title(),
    'after_title' => thematic_after_title(),
    ),
    'action_hook' => 'thematic_header',
    'function' => 'thematic_header_aside',
    'priority' => 8,
    );
    return $content;
    }
    add_filter('thematic_widgetized_areas', 'add_header_aside');

    // And this is our new function that displays the widgetized area
    function thematic_header_aside() {
    if (is_sidebar_active('header-aside')) {
    echo thematic_before_widget_area('header-aside');
    dynamic_sidebar('header-aside');
    echo thematic_after_widget_area('header-aside');
    }
    }
    // First we remove the thematic_brandingopen() .. we're going to make one addition for this one.
    // And we remove thematic_access() .. will be added later unchanged with a priority of 10.
    function remove_branding() {
    remove_action('thematic_header','thematic_brandingopen',1);
    remove_action('thematic_header','thematic_access',9);
    }
    add_action('init', 'remove_branding');

    // We wrap #branding and #header-aside with #header-box
    function childtheme_brandingopen() { ?>
    <div id="header_box">
    <div id="branding">
    <?php }
    add_action('thematic_header','childtheme_brandingopen',1);

    // Now we need to close #header-box
    function header_box_close() { ?>
    </div>
    <?php }
    add_action('thematic_header', 'header_box_close', 9);

    // And we add the unchanged thematic_access() with the new priority 10
    add_action('thematic_header','thematic_access', 10);
    ?>

    I can drop a search box in my widget aera but I'd prefer to have it along my blog name.
    With this new code, I tested to add the first code you gave me. This is errore message:

    Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home3/polyglot/public_html/wp-content/themes/thematicsamplechildtheme/functions.php on line 13

    Sidenote- Merci pour ton soutien! J'ai hâte de ne plus hésiter 10 minutes pour poster un message sur ce forum... Ton français est très bon! Si tu veux devenir Polyglot, suis-le blog!^^

    MERCI!

    Posted 4 years ago #
  7. Hi

    I need your help! Please.

    I still don't know how to add the Google Search Box above the title!

    Summary:
    1. I want to add a Google Search Box above the title!
    2. Only the Google Search box without a widget is OK.

    My function file:

    <?php
    function add_header_aside($content) {
    $content['Header Aside'] = array(
    'args' => array (
    'name' => 'Header Aside',
    'id' => 'header-aside',
    'before_widget' => thematic_before_widget(),
    'after_widget' => thematic_after_widget(),
    'before_title' => thematic_before_title(),
    'after_title' => thematic_after_title(),
    ),
    'action_hook' => 'thematic_header',
    'function' => 'thematic_header_aside',
    'priority' => 8,
    );
    return $content;
    }
    add_filter('thematic_widgetized_areas', 'add_header_aside');

    // And this is our new function that displays the widgetized area
    function thematic_header_aside() {
    if (is_sidebar_active('header-aside')) {
    echo thematic_before_widget_area('header-aside');
    dynamic_sidebar('header-aside');
    echo thematic_after_widget_area('header-aside');
    }
    }
    // First we remove the thematic_brandingopen() .. we're going to make one addition for this one.
    // And we remove thematic_access() .. will be added later unchanged with a priority of 10.
    function remove_branding() {
    remove_action('thematic_header','thematic_brandingopen',1);
    remove_action('thematic_header','thematic_access',9);
    }
    add_action('init', 'remove_branding');

    // We wrap #branding and #header-aside with #header-box
    function childtheme_brandingopen() { ?>
    <div id="header_box">
    <div id="branding">
    <?php }
    add_action('thematic_header','childtheme_brandingopen',1);

    // Now we need to close #header-box
    function header_box_close() { ?>
    </div>
    <?php }
    add_action('thematic_header', 'header_box_close', 9);

    // And we add the unchanged thematic_access() with the new priority 10
    add_action('thematic_header','thematic_access', 10);
    ?>

    Thank you so much!

    Posted 3 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.