Multisite-Language-Switcher icon indicating copy to clipboard operation
Multisite-Language-Switcher copied to clipboard

Link problem

Open crizzler opened this issue 8 years ago • 6 comments

Links to translated posts do not work like in Version 1.0.4.

Version 1.0.4 link structure: domain.tld/blog/post Version 1.0.6 link structure: domain.tld/post

Changing site settings or perma link structure has no effect.

crizzler avatar Dec 12 '15 20:12 crizzler

Thanks. I will check this now.

lloc avatar Jan 14 '16 13:01 lloc

I experienced the same issue with translated posts. No matter if I change the permalink, the language switcher keeps redirecting me from /en/blog to /de and vice versa. Same issue with posts. Is there any solution for this by now? Thanks in advance.

f4z3k4s avatar Feb 02 '16 10:02 f4z3k4s

Do you have an URL where I can see this?

lloc avatar Feb 02 '16 11:02 lloc

Thanks for the quick reply. The url is the following: http://quercusapp.com . If you click on about then select blog and you press on 'DEUTSCH' it jumps to the frontpage of the german version, although the german blog is selected in the language switcher. Same goes with posts. We struggled hours with figuring out what could cause this and haven't been able to solve this yet. Thank you for helping us!

f4z3k4s avatar Feb 02 '16 17:02 f4z3k4s

Is that a problem with the plugin itself? Or are we not doing something correctly perhaps?(We just did the same thing as with the other pages). Or is the problem related to Wordpress?

f4z3k4s avatar Feb 04 '16 08:02 f4z3k4s

This definitely needs to be fixed in the core code. For the time being, here is a function I wrote that generates all the data you need to output a custom language selector that actually works as intended.

public function get_language_options()
{
    global $post;

    $blogs = MslsBlogCollection::instance()->get_objects();
    $posts = ($post) ? get_option('msls_' . $post->ID) : [];

    $current = null;
    $links = [];

    foreach($blogs as $blog) {
        $language = $blog->get_language();

        if ($blog->userblog_id == MslsBlogCollection::instance()->get_current_blog_id()) {
            $current = $language;
        }

        // if linked post doesn't exist, link to homepage
        $links[$language] = $blog->path;

        if (isset($posts[$language])) {
            switch_to_blog($blog->userblog_id);
            $links[$language] = get_permalink($posts[$language]);
            restore_current_blog();
        }
    }

    return [
        'current' => $current,
        'links' => $links
    ];
}

jeffturcotte avatar Jul 17 '17 15:07 jeffturcotte