WordPress.org

Ready to get started?Download WordPress

Forums

qTranslate
[resolved] (Hide Content which is not available for the selected language) not working (6 posts)

  1. was955
    Member
    Posted 1 year ago #

    hi
    i am using latest wordpress 3.4.2 with qTranslate Version 2.5.32
    this function
    (Hide Content which is not available for the selected language)
    is not working!
    i tried new posts and converting as the advanced settings do with no luck.
    can someone point me to way for the solution.
    i am using 3 languages en,ar,he. (English,Arabic,Hebraw)

    http://wordpress.org/extend/plugins/qtranslate/

  2. was955
    Member
    Posted 1 year ago #

    well after trying on new clean site i found the problem was from the theme itself as it is using different loops with filters.

    i still didn't fix it but i found that the nav-menu is not hiding too.

    well more to explore.

  3. was955
    Member
    Posted 1 year ago #

    to hide the content in the menu add this code in the functions.php

    class WgQtranslate {
    
    	public function __construct()
    	{
    		// Hide non translated menu items
    		add_filter( 'wp_nav_menu_objects', array( &$this, 'hide_untranslated_menu_items' ) );
    	}
    
    	/**
    	 * Retrieves a list of available languages for specific post. The native
    	 * function at qTranslate did always add the current language to the set.
    	 *
    	 * @param int $post_id
    	 * @param string $language
    	 * @return void
    	 * @author Erik Hedberg (erik@webbgaraget.se)
    	 */
    	private function _getAvailableLanguages( $post_id, $language )
    	{
    		global $q_config;
    		$post = &get_post($post_id);
    		$languages = array();
    		$content = qtrans_split($post->post_content);
    		foreach($content as $lang => $lang_text) {
    			$lang_text = trim($lang_text);
    			if(!empty($lang_text)) $languages[] = $lang;
    		}
    		if(sizeof($languages)==0) {
    			// add default language to keep default URL
    			$languages[] = $q_config['language'];
    		}
    		if($language == '') $language = $q_config['default_language'];
    		return in_array($language, $languages);
    	}
    
    	/**
    	 * Excludes all menu items that aren't translated
    	 *
    	 * @param string $objects
    	 * @return void
    	 * @author Erik Hedberg (erik@webbgaraget.se)
    	 */
    	public function hide_untranslated_menu_items( $objects )
    	{
    		$new_list = array();
    		foreach( $objects as $object )
    		{
    			$page_id = get_post_meta( $object->ID, '_menu_item_object_id', true );
    			if ( $page_id && $this->_getAvailableLanguages( $page_id, qtrans_getLanguage() ) )
    			{
    				$new_list[] = $object;
    			}
    		}
    		return $new_list;
    	}
    }
    new WgQtranslate();
  4. was955
    Member
    Posted 1 year ago #

    one last thing if u get in the slider 3 languages all together

    then go the slider php and add this code

    qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage()

    to the echo function like this

    before:

    $return .= '<p class="flex-caption">'.$caption.'</p>';

    after:

    $return .= '<p class="flex-caption">'.qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($caption).'</p>';
  5. benji337
    Member
    Posted 1 year ago #

    Hi was955,
    i am a new user of wordpress and qtranslate in particulary.
    your help to hide the content in the menu ... was realy very usful for me.

    10-x a lot for sharing your knowledge

  6. was955
    Member
    Posted 1 year ago #

    yes no problem tell how can i help you

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic