Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I know qTranslate has the option to hide untranslated content, but that doesn't seem to work. I.e: I have a website with three languages: Dutch, French and English. There is one particular page that has some subpages that are only available in Dutch. I want them to show up on the Dutch website, but hide them completely from the French and English site. Like so:

  • MenuItem1
  • MenuItem2
    • MenuItem2.1
    • MenuItem2.2
  • MenuItem3

So MenuItem2 and it's subpages are only available in Dutch. I want them hidden on the English/French website.

Is this possible with qTranslate, or another plugin? Or is there a piece of code that will allow this?

Thanks.

share|improve this question
    
Any other solutions than the one below? ie using filters? –  alekwisnia Oct 17 '12 at 12:03

4 Answers 4

This might help: http://www.gish.se/wg-qtranslate.zip - download and install, then fix plugin, changing:

foreach($content as $language  => $lang_text) {
         $lang_text = trim($lang_text);
         if(!empty($lang_text)) $languages[] = $language ;
      }

to

foreach($content as $lang  => $lang_text) {
         $lang_text = trim($lang_text);
         if(!empty($lang_text)) $languages[] = $lang ;
      }

taken from http://www.qianqin.de/qtranslate/forum/viewtopic.php?f=3&t=2958, works in most cases

share|improve this answer
    
Has anyone used this plugin? It works for pages and one category link out of three and got not idea why it doesn't work with another two. –  alekwisnia Oct 22 '12 at 14:59
    
Weird. Deleting category, adding new one and moving posts to this new category seems to fix the above problem... –  alekwisnia Oct 23 '12 at 9:22
up vote 0 down vote accepted

Little hack in my submenu code:

function hierarchical_submenu($post) {
    $top_post = $post;
    // If the post has ancestors, get its ultimate parent and make that the top post
    if ($post->post_parent && $post->ancestors) {
        $top_post = get_post(end($post->ancestors));
    }
    // Always start traversing from the top of the tree
    return hierarchical_submenu_get_children($top_post, $post);
}

function hierarchical_submenu_get_children($post, $current_page) {
    $menu = '';
    // Get all immediate children of this page
    $children = get_pages('child_of=' . $post->ID . '&parent=' . $post->ID . '&sort_column=menu_order&sort_order=ASC');
    if ($children) {
        $menu = "\n<ul>\n";
        foreach ($children as $child) {
            // If the child is the viewed page or one of its ancestors, highlight it
            if (in_array($child->ID, get_post_ancestors($current_page)) || ($child->ID == $current_page->ID)) {
                $menu .= '<li class="active"><a href="' . get_permalink($child) . '" class="first-li active">' . $child->post_title . '</a>';
            } else {
                if (strcmp($child->post_title, " ")) {
                    $menu .= '<li><a href="' . get_permalink($child) . '">' . $child->post_title . '</a>';
                }
            }
            // If the page has children and is the viewed page or one of its ancestors, get its children
            if (get_children($child->ID) && (in_array($child->ID, get_post_ancestors($current_page)) || ($child->ID == $current_page->ID))) {
                $menu .= hierarchical_submenu_get_children($child, $current_page);
            }
            $menu .= "</li>\n";
        }
        $menu .= "</ul>\n";
    }
    return $menu;
}

Added the

if (strcmp($child->post_title, " ")) {
                        $menu .= '<li><a href="' . get_permalink($child) . '">' . $child->post_title . '</a>';
                    }

If structure here.

share|improve this answer

I create a very simple plugin which enables hiding menu items in some languages, but show them on others.
After installing my plugin and enabling it, you just need to remove the title from the unwanted language, but leave the string in the others.
For example if you want to show "Company Profile" only in the English menu, but not in the French menu (or any other language), you set the menu item title to: "Company Profile".
The default behavior of qTranslate would give you item "Company Profile (English)" in the French menu.
Enjoy: http://www.hoojima.com/wordpress/qtranslate-remove-menu-item.zip

share|improve this answer
    
Don't you have a Git of it? Or give the link and summary of the plugin's page? Instead of linking directly to a zip file... I mean, it's not very common here... –  brasofilo Dec 3 '12 at 22:06

I did the following in my theme's functions.php:

if (function_exists('qtrans_getLanguage')):
function mytheme_qt_menu_filter($items) {
    $filtered = array();
    foreach ($items as $item) {
        // TODO Not sure what happens when object_id == ID, which happens if
        //      not linking to post (e.g. external link).
        if (qtrans_isAvailableIn($item->object_id, qtrans_getLanguage()))
            $filtered[] = $item;
    }
    return $filtered;
}
add_filter('wp_get_nav_menu_items', 'na_qt_menu_filter');
endif;

It seems to work in my case :)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.