• Resolved BeeCee

    (@csigncsign)


    Hi,

    the “Quicklinks” are not in the right place in my posts and pages where I would like them to be due to using a LayoutBuilder.

    So could you please give me the code snippet for the output of the “Quicklinks”, so that I could add it into my single.php and page.php or alternatively in my functions.php please?

    View post on imgur.com

    Thank you.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support dinamiko

    (@dinamiko)

    Hi csigncsign,

    You can use get_translations function to output a list of language links, here is an example that adds the menu before the content. As you can see we are using FALSE in include_base argument, that way current site is not added in the result:

    add_filter( 'the_content', function( $content ) {
    
        $items = mlp_custom_get_language_items();
    
        $output = '<ul>';
        foreach ( $items as $item ) {
            $output .= '<li><a href="'. esc_url($item['url']) .'">'. esc_attr($item['name']) .'</a></li>';
        }
        $output .= '</ul>';
    
        return $output . $content;
    });
    
    /**
     * Get language items.
     *
     * @return array|void
     */
    function mlp_custom_get_language_items() {
    
        $api = apply_filters( 'mlp_language_api', NULL );
        if ( ! is_a( $api, 'Mlp_Language_Api_Interface' ) ) {
            return;
        }
    
        /**
         * @type int    $site_id      Base site
         * @type int    $content_id   post or term_taxonomy ID, *not* term ID
         * @type string $type         @see Mlp_Language_Api::get_request_type()
         * @type bool   $strict       When TRUE (default) only matching exact
         *                                 translations will be included
         * @type string $search_term  If you want to translate a search
         * @type string $post_type    For post type archives
         * @type bool   $include_base Include the base site in returned list
         */
        $translations_args = array(
            'strict'       => FALSE,
            'include_base' => FALSE,
        );
        $translations      = $api->get_translations( $translations_args );
        if ( empty( $translations ) ) {
            return;
        }
    
        $items = array();
        /** @var Mlp_Translation_Interface $translation */
        foreach ( $translations as $site_id => $translation ) {
    
            $url = $translation->get_remote_url();
            if ( empty( $url ) ) {
                continue;
            }
    
            $language = $translation->get_language();
            $active   = FALSE;
            if ( get_current_blog_id() === $site_id ) {
                $active = TRUE;
            }
    
            $items[ $site_id ] = array(
                'url'    => $url,
                'http'   => $language->get_name( 'http' ),
                'name'   => $language->get_name( 'native' ),
                'active' => $active,
            );
        }
    
        return $items;
    }

    Thanks,
    Emili

    Thread Starter BeeCee

    (@csigncsign)

    meanwhile I have found in another forum a better and shorter way:

    function mlp_show_linked_elements_mod() {
    	if( function_exists( 'mlp_show_linked_elements' ) ) {
    		return mlp_show_linked_elements( 
    			array(
    			'link_text' => 'flag', // oder 'text' oder 'text_flag'
    			'show_current_blog' => TRUE   // TRUE - display the current language, FALSE - hide the current language (default)
    			) 
    		);
    	}
    	
    }
    
    add_shortcode( 'mlp_show', 'mlp_show_linked_elements_mod' ); 

    and then use the shortcode

    [mlp_show]

    or alternatively for the theme’s function.php:

    add_action( 'avia_meta_header', 'avia_mlp_language_switch', 10);
    function avia_mlp_language_switch()
    {
    if(function_exists( 'mlp_show_linked_elements' )) mlp_show_linked_elements( array( 'link_text' => 'flag', 'show_current_blog' => FALSE ) );
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Template code snippet for “Quicklinks”?’ is closed to new replies.