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

Theme localization in a query... WordPress

  • SOLVED


Hello,

I am localizing my theme up for translation strings.

Using generic... <h5><?php _e('Contact','mytheme'); ?></h5>

But I've got some query's that include text in the query itself.

Example...

<?php wp_list_bookmarks(array(
'orderby' => 'rating',
'order' => 'ASC',
'limit' => 10,
'category_name' => 'Our Friends',
'title_before' => '<h5>',
'title_after' => '</h5>',
'link_before' => '<span>&#187;</span> '
) ); ?>


How do I localize the the 'Our friends' text?

I've tried this...

<?php wp_list_bookmarks(array(
'orderby' => 'rating',
'order' => 'ASC',
'limit' => 10,
'category_name' => . __('Our Friends', 'mytheme') .,
'title_before' => '<h5>',
'title_after' => '</h5>',
'link_before' => '<span>&#187;</span> '
) ); ?>


But this does not work?

Any ideas...


Also while on i'm topic... I have the same problem with stuff in my functions...

function search_form_header( $form ) {
$form = '<form method="get" id="searchform-header" action="' . home_url( '/' ) . '" >
<div>
<input class="pie" type="text" value="" name="s" id="s" />
<input class="pie" type="submit" id="searchsubmit" value="'. esc_attr__('Search') .'" />
<input type="hidden" name="lang" value="' . __ (ICL_LANGUAGE_CODE) . '"/>
</div>
</form>';
return $form;
}
add_filter( 'get_search_form', 'search_form_header' );


If you look at... value="'. esc_attr__('Search') .'"

How do I localize this?


Thanks
Josh

Answers (3)

2012-01-27

Francisco Javier Carazo Gil answers:

Hi Josh,

Before executing this:

<?php wp_list_bookmarks(array(

'orderby' => 'rating',

'order' => 'ASC',

'limit' => 10,

'category_name' => . __('Our Friends', 'mytheme') .,

'title_before' => '<h5>',

'title_after' => '</h5>',

'link_before' => '<span>&#187;</span> '

) ); ?>



You have to save value of category_name in a var and then call the query with this var.


Francisco Javier Carazo Gil comments:

Something like this:
$my_category_name = __('Our Friends', 'mytheme');

And then:
'category_name' => $my_category_name,


Josh Cranwell comments:

Hmmm... I'm not sure how to do this?


Francisco Javier Carazo Gil comments:

Josh,

You have to do: $my_category_name = __('Our Friends', 'mytheme');

Before calling:


wp_list_bookmarks


Francisco Javier Carazo Gil comments:

And into wp_list_bookmarks you have to use this:
'category_name' => $my_category_name,


Josh Cranwell comments:

Perfecto!!!

Thank you!


Josh Cranwell comments:

Perfecto!!!

Thank you!

2012-01-27

Luis Abarca answers:

First, you can use category ID instead of category name

<?php wp_list_bookmarks(array(
'orderby' => 'rating',
'order' => 'ASC',
'limit' => 10,
<strong> 'category' => "2", // the category ID of "Our friends"</strong>
'title_before' => '<h5>',
'title_after' => '</h5>',
'link_before' => '<span>&#187;</span> '
) ); ?>


Second, just add the domain

function search_form_header( $form ) {
$form = '<form method="get" id="searchform-header" action="' . home_url( '/' ) . '" >
<div>
<input class="pie" type="text" value="" name="s" id="s" />
<input class="pie" type="submit" id="searchsubmit" value="'. <strong>esc_attr__('Search', 'yourtheme')</strong> .'" />
<input type="hidden" name="lang" value="' . __ (ICL_LANGUAGE_CODE) . '"/>
</div>
</form>';
return $form;
}

add_filter( 'get_search_form', 'search_form_header' );


Luis Abarca comments:

You can use get_term_by, ti get the category ID

<?php

<strong>$ourfriends = get_term_by('slug', 'our-friends', 'category'); </strong>

wp_list_bookmarks(array(
'orderby' => 'rating',
'order' => 'ASC',
'limit' => 10,
'category' => $ourfriends->term_id, // the category ID of "Our friends"
'title_before' => '<h5>',
'title_after' => '</h5>',
'link_before' => '<span>&#187;</span> '
) );

?>


Josh Cranwell comments:

Thanks Luis, the search worked...

How ever, on my other search form... it's not working....

See below value 'Search Downloads'

function search_form_download( $form ) {
$form = '<form method="get" id="searchform-download" action="' . home_url( '/' ) . '" >
<div>
<input type="text" value="' . __('Search Downloads','mytheme') . '" name="s" id="s-download" class="clearit" />
<input type="hidden" name="post_type" value="download" />
<input type="hidden" name="lang" value="' . __ (ICL_LANGUAGE_CODE) . '"/>
</div>
</form>';
return $form;
}


Have I done it wrong? Thanks


Luis Abarca comments:

Try to change the function to esc_attr__()

function search_form_download( $form ) {
$form = '<form method="get" id="searchform-download" action="' . home_url( '/' ) . '" >
<div>
<input type="text" value="' . <strong>esc_attr__('Search Downloads','mytheme')</strong> . '" name="s" id="s-download" class="clearit" />
<input type="hidden" name="post_type" value="download" />
<input type="hidden" name="lang" value="' . __ (ICL_LANGUAGE_CODE) . '"/>
</div>
</form>';

return $form;
}


Josh Cranwell comments:

No it worked the first time, it was WPML not registering new strings on browser refresh. Thanks for you help :-)

2012-01-27

John Cotton answers:

Have you tried with that line reading:

'category_name' => __('Our Friends', 'mytheme'),

?


Josh Cranwell comments:

Hi John,

Thanks for help, think Francisco J answered first