Forum Replies Created

Viewing 3 replies - 1 through 3 (of 3 total)
  • Forum: Plugins
    In reply to: [Polylang] Polylang
    Thread Starter LudovicB

    (@ludovicb)

    Ok, problems 1, 2 and 3 are SOLVED due to the following code, rewritten by a geeky friend of mine :

    // Initializing the theme's options for front-end usage
    function typominima() {
    	global $typominima;
    	$typominima = get_option('Typominima');
    }
    add_action('wp_head','typominima');
    
    if(function_exists('add_theme_support')) {
    
    	// Adds support for post thumbnails
    
    	add_theme_support('post-thumbnails');
    
    	// Register top custom menu
    
    	add_theme_support( 'menus' );
    
    	if(function_exists('register_nav_menus')) {
    		register_nav_menus(array(
    			'top-menu' => __( 'Top Menu' ),
    		));
    	}
    
    }
    
    // Top menu checker & builder
    
    function typominima_nav_menu() {
    	if(function_exists('wp_nav_menu')) {
    $typominima_nav_menu = wp_nav_menu(array('theme_location' => 'top-menu', 'container' => '', 'fallback_cb' => 'wp_page_menu', 'echo' => false, 'depth' => 2));
    
    	}
    	else {
    		$typominima_nav_menu = '<ul class="menu">'.wp_list_pages('sort_column=menu_order&title_li=&echo=0&depth=2').'</ul>';
    	}
    	echo $typominima_nav_menu;
    }

    Problem 4 remains, but I guess that for a coder, that’s not a complex problem.

    LudovicB

    (@ludovicb)

    The following code (the long one that I paste in the end of this message, and that is meant to be put in the end of the functions.php of your current theme) adapts the one by AndyDeGroo.
    It is still called by a

    <div class="translations-list">
    	<?php
    	if(function_exists('pll_the_post_translations'))
    		pll_the_post_translations();
    	?>
    </div>

    that you put where you need it in your theme (ex, page.php, archives.php, etc).

    It lists the available translations of the current posts.

    Put
    $this->register_string('others', 'others');
    just after the code

    $this->register_string(__('Site Title'), get_option('blogname'));
    $this->register_string(__('Tagline'), get_option('blogdescription'));
    $this->register_string(__('Date Format'), get_option('date_format'));
    $this->register_string(__('Time Format'), get_option('time_format'));

    in the file plugins/polylang/include/admin.php

    –> It displays a text before the result, a text that is editable ?? in the settings of Polylang (Dashboard / Settings / Languages / Strings translation).

    if(class_exists('Polylang_Base') && !function_exists('pll_languages_list')){
    
    	/**
    	 * Gets list of Polylang languages
    	 * @param boolean $hide_empty Optional, default is to return all language taxonomies.
    	 * @return array Array of language taxonomy term objects
    	 */
    	function pll_languages_list($hide_empty = FALSE){
    		global $polylang;
    		$langs = array();
    		if( $polylang instanceof Polylang_Base ){
    			$langs = (array)$polylang -> get_languages_list($hide_empty);
    		}
    		return $langs;
    	}
    
    	/**
    	 * Template tag to display other languages of a post
    	 * @param int $post_id Optional post ID, defaults to current post in the loop
    	 * @param array $args Optional arguments list
    	 */
    	function pll_the_post_translations($post_id = NULL, $args = array()){
    		global $post;
    		$defaults = array(
    			'sep' => "\n",
    			'before' => pll__('others').':<br/><ul class="translations">',
    			'after' => '</ul>',
    			'echo' => TRUE,
    		);
    		$args = wp_parse_args($args, $defaults);
    		extract($args, EXTR_SKIP);
    
    		$the_post = ($post_id !== NULL)? get_post($post_id) : $post;
    		$languages = pll_languages_list();
    		$current_lang = pll_current_language();
    
    		$output = ''; $outarr = array();
    		if($languages && isset($the_post->ID)){
    			foreach($languages as $lang){
    				$translated_id = (int)pll_get_post($the_post->ID, $lang->slug);
    				if(!$translated_id || $current_lang == $lang->slug){
    					continue;
    				}
    				$tranlated_link = get_permalink($translated_id);
    				$class = ($current_lang == $lang->slug) ? 'current' : '';
    				$outarr[] = '<li class="'.$class.'"><a href="'.esc_url($tranlated_link).'" hreflang="'.esc_attr($lang->slug).'">'.esc_html(get_the_title($translated_id)).' ('.$lang->name.')</a></li>';
    			}
    			if (count($outarr)) {
    $output = $before . implode($sep, $outarr) . $after;
    }
    		}
    		if(!$echo)
    			return $output;
    		 echo $output;
    	}
    }
    
    ?>

    Hope it works for you!
    Don’t thank me, it’s a friend of mine who did the modifications.

    Forum: Plugins
    In reply to: [Polylang] Polylang
    Thread Starter LudovicB

    (@ludovicb)

    I guess the problem is there, in my functions.php :

    // Initializing the theme's options for front-end usage
    function typominima() {
    	global $typominima;
    	$typominima = get_option('Typominima');
    }
    add_action('wp_head','typominima');
    
    if(function_exists(add_theme_support)) {
    
    	// Adds support for post thumbnails
    
    	add_theme_support('post-thumbnails');
    
    	// Register top custom menu
    
    	add_theme_support( 'menus' );
    
    	if(function_exists('register_nav_menus')) {
    		register_nav_menus(array(
    			'top-menu' => __( 'Top Menu' ),
    		));
    	}
    
    }
    
    // Top menu checker & builder
    
    function typominima_nav_menu() {
    	if(function_exists(wp_nav_menu)) {
    		$typominima_nav_menu = wp_nav_menu(array('menu' => 'Top Menu', 'container' => '', 'fallback_cb' => 'wp_page_menu', 'echo' => false, 'depth' => 2));
    	}
    	else {
    		$typominima_nav_menu = '<ul class="menu">'.wp_list_pages('sort_column=menu_order&title_li=&echo=0&depth=2').'</ul>';
    	}
    	echo $typominima_nav_menu;
    }

    I defined 3 menus according to the language chosen:
    Principal = french
    Main = english
    Main DE = german.

    Sorry for the bad title of my first post, it wasn’t clear…

Viewing 3 replies - 1 through 3 (of 3 total)