Anyway, I've been scratching my head on how to integrate qTranslate with the new Nav Menu feature in WP3 (Appearance > Menus)... I might have missed something, but anyway....
#1 [Solved]
First of all, in regards to directing the menu links (created using the Nav Menu feature) to the current language... The plugin works to some degrees, but failed when linking to posts from custom post types (at least this is my experience)... and also the link doesn't work when creating custom links, such as a 'Home' link, and I'm doing a lot of custom links on my current project...
I don't know if anybody had found a solution yet... without resorting to hard-coding the menu, that is... So I went to search for a solution and found this really neat trick: http://www.kriesi.at/archives/improve-y ... nu-output/
From this knowledge, I came up with this code:
- Code: Select all
// QTRANSLATE NAV MENU INTEGRATION //
class qtrans_walker extends Walker_Nav_Menu
{
function start_el(&$output, $item, $depth, $args)
{
global $wp_query;
$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
$class_names = $value = '';
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
$class_names = ' class="'. esc_attr( $class_names ) . '"';
$output .= $indent . '<li id="menu-item-'. $item->ID . '"' . $value . $class_names .'>';
$attributes = ! empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) .'"' : '';
$attributes .= ! empty( $item->target ) ? ' target="' . esc_attr( $item->target ) .'"' : '';
$attributes .= ! empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) .'"' : '';
// Determine integration with qTranslate Plugin
if (function_exists('qtrans_convertURL')) {
$attributes .= ! empty( $item->url ) ? ' href="' . qtrans_convertURL(esc_attr( $item->url )) .'"' : '';
} else {
$attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) .'"' : '';
}
$item_output = $args->before;
$item_output .= '<a'. $attributes .'>';
$item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
$item_output .= '</a>';
$item_output .= $args->after;
$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
}
}
Basically, I just changed this line:
- Code: Select all
$attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) .'"' : '';
To this:
- Code: Select all
// Determine integration with qTranslate Plugin
if (function_exists('qtrans_convertURL')) {
$attributes .= ! empty( $item->url ) ? ' href="' . qtrans_convertURL(esc_attr( $item->url )) .'"' : '';
} else {
$attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) .'"' : '';
}
Notice the use of qtrans_convertURL()...
Then you just add 'walker' => new qtrans_walker() to your wp_nav_menu function call like so:
- Code: Select all
wp_nav_menu( array(
'container' =>false,
'menu_class' => 'nav',
'echo' => true,
'before' => '',
'after' => '',
'link_before' => '',
'link_after' => '',
'depth' => 0,
'walker' => new qtrans_walker()
));
I guess this will make the links more qTranslate proof...
#2 [Unsolved]
Secondly, I wonder how we can beautify the appearance of the posts/pages titles both in the selection panels and in the menu editor panel.
Currently it shows '<!--:id-->Test ID<!--:--><!--:en-->Test EN<!--:-->', which is very ugly and unpleasant... and we are forced to use '[:en]Test EN[:id]Test ID' when creating custom link titles, which is quite inconvenient for clients.
Anybody knows how we can display only the current languages for the selection panels? And to have an extra field for translation in the menu editor panel?? Maybe from the knowledge that I provided above??
Thank you to the sharing community! Many thanks to Qian for the great plugin!!
Hope to hear from you guys!
Cheers!!
