• I am developing a wordpress template, and am using qTranslate to allow for English and French versions.
    The site is made of all static pages, and for most of them (index.php) I am outputting the content in a wp_query loop, with no problems.

    The problem is on my home page. The idea is to have a short summary of a few different pages displayed, and I would like the admin to be able to specify which pages to display in a custom menu (ie. in Appearance -> Menus).

    On home.php, I loop through that menu, and display the selected page:

    $menuName = 'home-page';
    $args = array(
    	'theme-location' => $menuName,
    	'depth' => 1
    );
    $locations = get_registered_nav_menus();
    $menu = wp_get_nav_menu_object( $locations[ $menuName ] );
    $menu_items = wp_get_nav_menu_items($menu->term_id, $args);
    $menu_items = apply_filters( 'get_pages', $menu_items );
    
    $output = '';
    foreach ($menu_items as $thisPage ) {
     $content = apply_filters('the_content', __($thisPage->post_content));
     $output .= // (some containing div html...)
               . $content
               . // (closing divs..);
    }
    echo $content;

    Unfortunately, the page content is showing in both languages. Taking a look at my $page object, I see that the post_type is not ‘page’, but ‘nav_menu_item’ — I am guessing this is the issue. The page also has a different ID as a nav_menu_item than as a ‘page.’

    I would really appreciate the help. I have been pounding my head against this for the past few days. I really like the easy admin interface for qTranslate, but if you know of other multi-language plugins that might do the job better, I would love to hear!
    I’m also interested in hearing whole-new-approaches.

    Here’s the page: http://edanschwartz.com/projects/adeline/fr/
    I’ve printed out the $page object I’m working with, and also the same page using get_page(‘id‘). For testing, there is only one post on the custom menu (for now).

    Thanks for the help!

Viewing 1 replies (of 1 total)
  • Thread Starter schw0722

    (@schw0722)

    It never fails: post a question on a forum, and within an hour you figure it out yourself.

    So for anyone else looking, here’s the solution:

    The nav_menu_item object has a property named ‘object_id’, which is actually the ID for the original page. So can grab that ID, and then get that original page, which qTranslate has no problem with.

    Here’s the code:

    $menuName = 'home-page';
    $args = array(
    	'theme-location' => $menuName,
    	'depth' => 1
    );
    $locations = get_registered_nav_menus();
    $menu = wp_get_nav_menu_object( $locations[ $menuName ] );
    $menu_items = wp_get_nav_menu_items($menu->term_id, $args);
    $menu_items = apply_filters( 'get_pages', $menu_items );
    
    $output = '';
    foreach ($menu_items as $item) {
    	// qTRANSLATE HACK:
    	// Get actual page (type='page' not'nav_menu_item' <-- qTranslate is unable to directly translate nav_menu_items)
    	$page = get_page($item->object_id);
            $content = apply_filters('the_content', $page->post_content);
            $output .= $content;
    }
    echo $output;

    Yes, I’m doubling the number of calls to the server, so it might slow the page down a bit, but it works.

Viewing 1 replies (of 1 total)
  • The topic ‘qTranslate: How to use nav_menu_item post type?’ is closed to new replies.