QTranslate:隐藏未翻译的内容

时间:2012-07-24 作者:Matthias

我知道qTranslate可以选择隐藏未翻译的内容,但这似乎不起作用。一、 我有一个网站,有三种语言:荷兰语、法语和英语。有一个特定页面包含一些子页面,这些子页面只能用荷兰语显示。我想让他们出现在荷兰的网站上,但要对法语和英语网站完全隐藏。像这样:

菜单项1。1菜单项2。因此,MenuItem2及其子页面仅以荷兰语提供。我想把它们藏在英语/法语网站上。

qTranslate或其他插件是否可以实现这一点?或者是否有一段代码允许这样做?

谢谢

4 个回复
最合适的回答,由SO网友:Matthias 整理而成

我的子菜单代码有点小问题:

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;
}
添加了

if (strcmp($child->post_title, " ")) {
                        $menu .= \'<li><a href="\' . get_permalink($child) . \'">\' . $child->post_title . \'</a>\';
                    }
如果结构在这里。

SO网友:alekwisnia

这可能有助于:http://www.gish.se/wg-qtranslate.zip - 下载并安装,然后修复插件,更改:

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

foreach($content as $lang  => $lang_text) {
         $lang_text = trim($lang_text);
         if(!empty($lang_text)) $languages[] = $lang ;
      }
摘自http://www.qianqin.de/qtranslate/forum/viewtopic.php?f=3&t=2958, 大多数情况下有效

SO网友:Ronny Sherer

我创建了一个非常简单的插件,可以在某些语言中隐藏菜单项,但在其他语言中显示它们
安装并启用我的插件后,只需从不需要的语言中删除标题,但将字符串保留在其他语言中
例如,如果只想在英文菜单中显示“公司简介”,而不想在法文菜单(或任何其他语言)中显示“公司简介”,可以将菜单项标题设置为:“公司简介”
qTranslate的默认行为将在法语菜单中为您提供“公司简介(英语)”项
享受:http://www.hoojima.com/wordpress/qtranslate-remove-menu-item.zip

SO网友:Arild Matsson

在我的主题功能中,我做了以下几点。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;
我的情况似乎是这样的:)

结束

相关推荐