• Resolved wallenium

    (@wallenium)


    Hej folks,
    I have a small problem. I want to write a small plugin for Multisite Language Switcher… It is working as it should, but i have a small problem with the URL…

    I want to add a small link with a flag (available in English, German and French) to the index page (list of posts). The language name should be the link to the blog post in that language.

    $blogs = MslsBlogCollection::instance();
    foreach ($blogs->get() as $blog) {
      $language	= $blog->get_language();
      $langname	= $blog->get_description();
      $siteurl	        = $blog->siteurl;
      $siteid		= $blog->siteid;
    }

    The siteURL is just the https://subdomain.domain.tld/. How to get the Full link to the different language versions?

    https://www.ads-software.com/plugins/multisite-language-switcher/

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter wallenium

    (@wallenium)

    Ok. Additional Problem:

    $blogs			= MslsBlogCollection::instance();
    $mydata			= MslsOptions::create(get_the_ID());
    
    foreach ($blogs->get() as $blog) { var_dump($blog);
    			$language	= $blog->get_language();
    			$langname	= $blog->get_description();
    			$siteurl	= $blog->siteurl;
    			$siteid		= $blog->siteid;
    
    			// get the URL of the translation
    			switch_to_blog($blog->userblog_id);
    			var_dump($mydata->get_permalink($language));
    
    			// build the array with the languages https://www.ads-software.com/support/topic/check-if-the-post-has-translation?replies=3
    			if($mydata->has_value($language)){
    				if(isset($this->options['show_flags']) && $this->options['show_flags']){
    					$languages[]	= sprintf(
    						'<a href="%s" title="%s"><img src="%s" alt="Flag" class="nopin" /> %s</a>',
    						$siteurl,
    						$language,
    						plugins_url('/images/'.$language.'.svg' , __FILE__ ),
    						$langname
    					);
    				}else{
    					$languages[]	= sprintf(
    						'<a href="%s" title="%s">%s</a>',
    						$siteurl,
    						$language,
    						$langname
    					);
    				}
    			}
    			restore_current_blog();
    		}

    i thought that i am able to get the my data of the current POST Id on the index, switch to the blog with the ID of the translation and switch back. But… the link is still the site url and not the post URL… not sure where i am wrong..

    Plugin Author Dennis Ploetner

    (@realloc)

    I’m not sure if I got it but do you know this link?

    https://github.com/lloc/Multisite-Language-Switcher/wiki/Generate-the-output

    Please explain what you’d like to accomplish.

    Cheers,
    Dennis.

    Thread Starter wallenium

    (@wallenium)

    As described in the second post (i couldn’t edit my first) i want to get the URLs of the available languages of a known post id.

    Example: PostID 555 has an english, german and french post article. If you visit the german blog, i want to add a link to the other languages on the index (not on the detailed view as it already exists). For that, i need the links to the articles in more than one language.

    i fetched the data using

    $blogs			= MslsBlogCollection::instance();
    $mydata			= MslsOptions::create(get_the_ID());

    now i am able to get the details of the available languages minus the current one:

    foreach ($blogs->get() as $blog)
    problem: $siteurl = $blog->siteurl; does link to the index, not to the article itself. i tried to generate the link to the article using

    switch_to_blog($blog->userblog_id);
    			var_dump($mydata->get_permalink($language));

    within the foreach loop. But it links to the index as well. i am not sure how to get the article link.

    other problem: ($mydata->has_value($language) seems to be always false… not sure why..there seems to be an issue with my implementation. but not sure where. do you get my problem?

    Thread Starter wallenium

    (@wallenium)

    ok. I think i got a solution. i wrote a function to search all URLs. These URLs are added to an array and this array is used in the foreach. Smarter and easier. And working ??

    Plugin Author Dennis Ploetner

    (@realloc)

    MslsOptions is not the right choice in this case because it uses the ID of an object only when is_admin() is true. You could use

    $mydata = new MslsOptionsPost( $some_post_id );

    when you know it is something like a post.

    Look also here to see what the factory of MslsOption does:

    https://github.com/lloc/Multisite-Language-Switcher/blob/master/includes/MslsOptions.php#L70

    Cheers,
    Dennis.

    Thread Starter wallenium

    (@wallenium)

    Thanks a lot for that hint, that worked.

    Plugin Author Dennis Ploetner

    (@realloc)

    Ok, very good. ??

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Get the detailed URL to a post’ is closed to new replies.