Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Calling a widget into the header php file?? WordPress

  • SOLVED

I'm not sure how to go about doing this...

I want to call the translation widget into the area in the header and replace the search bar. I want to obviously do it without the title which is easy enough, I just don't give it one. But how would I go about ?hooking? into the header?

[[LINK href="http://www.jezyk.pila.pl"]]jezyk.pila.pl[[/LINK]]

Answers (4)

2012-01-22

Arnav Joy answers:

hello can you give me access to your site I will make it , it is just replacing the search form at header and placing the widget there.


Arnav Joy comments:

my skype is : arnav.joy


Arnav Joy comments:

go to functions.php
and the end of the file add these code

register_sidebar(array(

'name' => 'HeaderTranslationWidget',

'id' => 'header-translation-widget',

'description' => 'This widgets is used for the header.',

'before_title' => '<h1>',

'after_title' => '</h1>'

));


and call this at the place where search form is defined

means just replace following code

<div id="search-form">

<form method="get" id="searchform" action="<?php echo home_url(); ?>/">



<input type="text" value="<?php esc_attr_e('Search this site...', 'Chameleon'); ?>" name="s" id="searchinput" />



<input type="image" src="<?php bloginfo('template_directory'); ?>/images/search_btn.png" id="searchsubmit" />



</form>

</div>

with the following code at header.php

<?php dynamic_sidebar('header-translation-widget') ?>

Now just got to Appereance>>Widgets at admin panel and drag drop translation widget to this newlly created widget.

See You!!!


Doug Montgomery comments:

This broke something...take a look....

jezyk.pila.pl


Arnav Joy comments:

add the code in functions.php
at the end of the file and just befor the ?> tag


Arnav Joy comments:

can you come on skype

arnav.joy

or paste your functions.php here i will make it


Arnav Joy comments:

any code in php files must come under <?php --all the code--- ?>

so you have placed that code after the ?>
that's why it is visible at the browser and working as a normal text rather than as a php code


Doug Montgomery comments:

I got it...search bar is gone but not widget area in the backend. What am I missing here? hmmm....


Doug Montgomery comments:

I got it...search bar is gone but not widget area in the backend. What am I missing here? hmmm....


Arnav Joy comments:

did you placed this in your header.php

<?php dynamic_sidebar('header-translation-widget') ?>


Doug Montgomery comments:

I want to Vote for you my friend but I'm a newbie here and they won't let me. Thanks for the help and getting it squared away for me.


Doug Montgomery comments:

duh...I got it...voted.

2012-01-22

Fahad Murtaza answers:

Which website url?


Fahad Murtaza comments:

and which translation widget? Please post the url for the plugin


Doug Montgomery comments:

mmmm..... jezyk.pila.pl


Doug Montgomery comments:

www.jezyk.pila.pl
http://transposh.org


Fahad Murtaza comments:

I see you are using this theme.

http://www.elegantthemes.com/gallery/chameleon/


Doug Montgomery comments:

Yes....
On the front page you'll see a translation widget about half way down on the left. I want to pull that widget up into the search bar.


Fahad Murtaza comments:

Some coding work needed. Give me admin access in a private message and I will get back to you.


Fahad Murtaza comments:

Looks like the header search form needs to be replaced with the php code which outputs the translation widget. This wont be simple drag and drop I believe.


Doug Montgomery comments:

Ya..I was looking at the code given to me by Luis...I can't make heads or tails of it...

2012-01-22

Luis Abarca answers:

You need to register and create a sidebar in the place you need the widget

Register in functions.php

register_sidebar(array(
'name' => 'HeaderSideBar',
'id' => 'header-sidebar',
'description' => 'Widgets in this area will be shown on the header.',
'before_title' => '<h1>',
'after_title' => '</h1>'
));


Add the place in header.php
dynamic_sidebar('header-sidebar')

Then assign the widget to the sidebar


Doug Montgomery comments:

Ya, I thought you were going to say something like that...The thing is...I don't know how to 'register' and 'create' a sidebar. php is great to me...


Doug Montgomery comments:

My header.php file....if it helps....

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>

<head profile="http://gmpg.org/xfn/11">

<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />

<title><?php elegant_titles(); ?></title>

<?php elegant_description(); ?>

<?php elegant_keywords(); ?>

<?php elegant_canonical(); ?>



<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" />

<link rel="stylesheet" href="<?php bloginfo('template_directory'); ?>/css/colorpicker.css" type="text/css" media="screen" />



<link href='http://fonts.googleapis.com/css?family=Droid+Sans:regular,bold' rel='stylesheet' type='text/css'/>

<link href='http://fonts.googleapis.com/css?family=Kreon:light,regular' rel='stylesheet' type='text/css'/>



<link rel="alternate" type="application/rss+xml" title="<?php bloginfo('name'); ?> RSS Feed" href="<?php bloginfo('rss2_url'); ?>" />

<link rel="alternate" type="application/atom+xml" title="<?php bloginfo('name'); ?> Atom Feed" href="<?php bloginfo('atom_url'); ?>" />

<link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" />



<!--[if lt IE 7]>

<link rel="stylesheet" type="text/css" href="<?php bloginfo('template_directory'); ?>/css/ie6style.css" />

<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/DD_belatedPNG_0.0.8a-min.js"></script>

<script type="text/javascript">DD_belatedPNG.fix('img#logo, span.overlay, a.zoom-icon, a.more-icon, #menu, #menu-right, #menu-content, ul#top-menu ul, #menu-bar, .footer-widget ul li, span.post-overlay, #content-area, .avatar-overlay, .comment-arrow, .testimonials-item-bottom, #quote, #bottom-shadow, #quote .container');</script>

<![endif]-->

<!--[if IE 7]>

<link rel="stylesheet" type="text/css" href="<?php bloginfo('template_directory'); ?>/css/ie7style.css" />

<![endif]-->

<!--[if IE 8]>

<link rel="stylesheet" type="text/css" href="<?php bloginfo('template_directory'); ?>/css/ie8style.css" />

<![endif]-->



<script type="text/javascript">

document.documentElement.className = 'js';

</script>



<?php if ( is_singular() ) wp_enqueue_script( 'comment-reply' ); ?>

<?php wp_head(); ?>



</head>

<body <?php body_class(); ?>>

<?php do_action('et_header_top'); ?>

<div id="container">

<div id="header" class="clearfix">

<a href="<?php bloginfo('url'); ?>">

<?php $logo = (get_option('chameleon_logo') <> '') ? get_option('chameleon_logo') : get_bloginfo('template_directory').'/images/logo.png'; ?>

<img src="<?php echo esc_url($logo); ?>" alt="Chameleon Logo" id="logo"/>

</a>

<p id="slogan"><?php bloginfo('description'); ?></p>

<?php do_action('et_header'); ?>



<?php $menuClass = 'nav';

$menuID = 'top-menu';

$primaryNav = '';

if (function_exists('wp_nav_menu')) {

$primaryNav = wp_nav_menu( array( 'theme_location' => 'primary-menu', 'container' => '', 'fallback_cb' => '', 'menu_class' => $menuClass, 'menu_id' => $menuID, 'echo' => false ) );

};

if ($primaryNav == '') { ?>

<ul id="<?php echo esc_attr($menuID); ?>" class="<?php echo esc_attr($menuClass); ?>">

<?php if (get_option('chameleon_home_link') == 'on') { ?>

<li <?php if (is_home()) echo('class="current_page_item"') ?>><a href="<?php bloginfo('url'); ?>"><?php esc_html_e('Home','Chameleon') ?></a></li>

<?php }; ?>



<?php show_page_menu($menuClass,false,false); ?>

<?php show_categories_menu($menuClass,false); ?>

</ul> <!-- end ul#nav -->

<?php }

else echo($primaryNav); ?>



<div id="additional-info">

<div id="et-social-icons">

<?php

$et_rss_url = get_option('chameleon_rss_url') <> '' ? get_option('chameleon_rss_url') : get_bloginfo('comments_rss2_url');

if ( get_option('chameleon_show_twitter_icon') == 'on' ) $social_icons['twitter'] = array('image' => get_bloginfo('template_directory') . '/images/twitter.png', 'url' => get_option('chameleon_twitter_url'), 'alt' => 'Twitter' );

if ( get_option('chameleon_show_rss_icon') == 'on' ) $social_icons['rss'] = array('image' => get_bloginfo('template_directory') . '/images/rss.png', 'url' => $et_rss_url, 'alt' => 'Rss' );

if ( get_option('chameleon_show_facebook_icon') == 'on' ) $social_icons['facebook'] = array('image' => get_bloginfo('template_directory') . '/images/facebook.png', 'url' => get_option('chameleon_facebook_url'), 'alt' => 'Facebook' );

$social_icons = apply_filters('et_social_icons', $social_icons);

if ( !empty($social_icons) ) {

foreach ($social_icons as $icon) {

echo "<a href='" . esc_url($icon['url']) . "' target='_blank'><img alt='" . esc_attr($icon['alt']) . "' src='" . esc_url($icon['image']) . "' /></a>";

}

}

?>

</div>



<div id="search-form">

<form method="get" id="searchform" action="<?php echo home_url(); ?>/">

<input type="text" value="<?php esc_attr_e('Search this site...', 'Chameleon'); ?>" name="s" id="searchinput" />

<input type="image" src="<?php bloginfo('template_directory'); ?>/images/search_btn.png" id="searchsubmit" />

</form>

</div> <!-- end #search-form -->

</div> <!-- end #additional-info -->

</div> <!-- end #header -->


Doug Montgomery comments:

Ok, did I really just do that? I feel like such a rookie...I didn't know it would stretch out like that...sorry about that...

Here's the short version...


<div id="search-form">
<form method="get" id="searchform" action="<?php echo home_url(); ?>/">

<input type="text" value="<?php esc_attr_e('Search this site...', 'Chameleon'); ?>" name="s" id="searchinput" />

<input type="image" src="<?php bloginfo('template_directory'); ?>/images/search_btn.png" id="searchsubmit" />

</form>



...I know this is what I want to replace but I don't know anything about <div>'s or where to place the dynamic_sidebar('header-sidebar').

Just looking at the functions.php...I have no idea where to put the code you gave above. It's literally greek to me.

2012-01-22

Duncan O'Neill answers:

You could take a completely different tack, and use the

[[LINK href="http://www.qianqin.de/qtranslate/"]]qtranslate plugin[[/LINK]]

Then all you need to do in the header is place this code where you want it;


if(function_exists('qtrans_generateLanguageSelectCode')) {
// Image Only :'image', Text Ony :'text',Both :'both'
qtrans_generateLanguageSelectCode('image');
}


The plugin allows language switching by use of small image flags, text, or both.

hth,


Doug Montgomery comments:

Thanks although gtranslate doesn't allow for saved user correction. Transposh will allow anyone to correct the translation.