Integration with WP3 Nav Menu Feature

Having Problems? Need Help? Post here!

Re: Integration with WP3 Nav Menu Feature

Postby side » Wed Jan 04, 2012 4:51 am

hi everybody,

although method 2 should work i still experience a problem:

i added method 2 to my functions.php at the very end and my "Home"-button issue should be resolved, because if i roll the pointer over the home button the correct link direct is displayed in my browser's status bar (.../de/home).
BUT: as soon as i click on the home button, the home page in turn is displayed in the default language (english), although the link was actually correct.
i am using an adapted coraline theme and WP 3.3., but it is obviously not a theme issue, as the problem occurs in other themes as well!

has anyone experienced the same?
Last edited by side on Mon Jan 09, 2012 5:42 pm, edited 1 time in total.
side
 
Posts: 2
Joined: Wed Jan 04, 2012 4:15 am

Re: Integration with WP3 Nav Menu Feature

Postby side » Mon Jan 09, 2012 5:42 pm

got it workin now!
for anyone else who has got the same problem and using coraline and a static home page:
do not use a custom link as home button! i created a new link for the home button in the menu using the wp creator for buttons linking to pages...will work fine then!
no idea why it won't work with custom links (as i stated above, it should work), but found a solution for me now!
side
 
Posts: 2
Joined: Wed Jan 04, 2012 4:15 am

Re: Integration with WP3 Nav Menu Feature [Thanks to bedex78]

Postby sariyanta » Fri Feb 10, 2012 4:35 pm

bedex78 wrote:Here's another method to direct the links correctly... This time using FILTER, so you can skip the 'Walker' argument in the wp_nav_menu function call.

Code: Select all
add_filter('walker_nav_menu_start_el', 'qtrans_in_nav_el', 10, 4);
function qtrans_in_nav_el($item_output, $item, $depth, $args){
    $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;
      
   return $item_output;
}


This one solve my problem, just added the code into my themes function.php and voila.... kini semua baik baik saja......
[:id]Terimakasih bedex78, [:en]Thank you bedex78, :D
sariyanta
 
Posts: 1
Joined: Fri Feb 10, 2012 4:30 pm

Re: Integration with WP3 Nav Menu Feature

Postby qlstudio » Tue Mar 20, 2012 9:54 am

@sariyanta - this function is close, but sometimes returns the wrong slug - and gives me 404 pages..

I need to fix custom links added via menus and shown using wp_nav_menu - these lose the language variable
qlstudio
 
Posts: 8
Joined: Mon Jan 30, 2012 8:49 pm

Re: Integration with WP3 Nav Menu Feature

Postby micha » Fri Mar 23, 2012 1:40 am

thank you sooooooooooooo much @bedex78 ,

this just worked after pasting it in my functions file... after hours agonizing over how to solve my custom links problems, this worked like a charm...
i think i love you :D

bedex78 wrote:Here's another method to direct the links correctly... This time using FILTER, so you can skip the 'Walker' argument in the wp_nav_menu function call.

Code: Select all
add_filter('walker_nav_menu_start_el', 'qtrans_in_nav_el', 10, 4);
function qtrans_in_nav_el($item_output, $item, $depth, $args){
    $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;
      
   return $item_output;
}
micha
 
Posts: 3
Joined: Fri Mar 23, 2012 12:38 am

Re: Integration with WP3 Nav Menu Feature

Postby todhirsch » Wed Mar 28, 2012 1:18 am

Sorry, coding newbie here dealing with this same problem. Is all I need to do is copy and paste this function into my functions.php file? Don't I have to specify the URLs somewhere? If so where? Thanks!
todhirsch
 
Posts: 1
Joined: Wed Mar 28, 2012 12:57 am

Re: Integration with WP3 Nav Menu Feature

Postby Atec » Sat Sep 22, 2012 7:32 pm

Thank you so much for this work !
I spent so many hours (and not only daytime) looking for a solution on this blog and somewhere else !
I tried solution 3 but id didn't work, no more solution 2.
At least I tried solution 1 but it didn't work either.
I noticed that the second language (/fr/ for my blog) was correctly inserted in menu links but links were returned to default language.
However a copy of menu link in a new browser tab was right to second language.
I just changed the parmalink from custom /%category%/%postname%/ to default and the miracle took place !
Maybe your 2nd and 3rd solution would work with default permalink setting too.

BTW I also use All-in-One Event Calendar perfectly in two languages.

Now I have just to fix another problem: switching automatically to browser language...

WP 3.3.1
qTtranslate: 2.5.28
Atec
 
Posts: 2
Joined: Sat Sep 22, 2012 4:31 pm

Re: Integration with WP3 Nav Menu Feature

Postby shimsy » Mon Oct 29, 2012 1:45 pm

This also worked perfectly for me, now my custom menu links point to the right place.
Thanks so much!
Thanks
-Graham

- https://shimsy.com
shimsy
 
Posts: 7
Joined: Sun Sep 30, 2012 4:27 pm
Location: UK, Hong Kong

Re: Integration with WP3 Nav Menu Feature

Postby inakigil » Wed Apr 17, 2013 11:10 am

Thanks!!! It works very good!! :D
inakigil
 
Posts: 2
Joined: Mon Aug 27, 2012 6:33 pm

Re: Integration with WP3 Nav Menu Feature

Postby lococo666 » Sun May 05, 2013 11:07 am

the links to customs post in the wp menu did not translate
the second method (by bedex78 » Wed Oct 06, 2010 8:20 pm) is working perfectly for me
thank you very much
lococo666
 
Posts: 1
Joined: Sat Mar 24, 2012 7:08 pm

Previous

Return to qTranslate Support Forum

Who is online

Users browsing this forum: No registered users and 6 guests