WordPress.org

Ready to get started?Download WordPress

Forums

Multisite Language Switcher
[resolved] Create a hardcoded link (7 posts)

  1. Carmdq
    Member
    Posted 1 year ago #

    Hi, I wonder how could I create a hardcoded link which is both, localizable and also works for my multisite install.

    I'm working on a site with two languages, and I want to have a "read all" link in each site that points to its respective blog.

    http://wordpress.org/extend/plugins/multisite-language-switcher/

  2. realloc
    Member
    Plugin Author

    Posted 1 year ago #

    I'm not sure if this should be done by the Multisite Language Switcher. Seems that you need a link (somewhere in your theme) which can be localized. Something like

    <a href="#"><?php_e('Hello user','mytheme'); ?></a>

    Read on here: http://wp.smashingmagazine.com/2011/12/29/internationalizing-localizing-wordpress-theme/

  3. Carmdq
    Member
    Posted 1 year ago #

    Hi realloc,

    you're correct. I'm trying to add a link in my theme (in the index page actually), that links to the blog.
    The thing is that I have two sites, one in English and the other one in Spanish. In both sites I wanted to add a link that takes you to the blog.
    But I have two blogs, as I have two sites.

    So,the English version of the site should link to the English blog and the Spanish site should link to the Spanish blog.

    I think I need some sort of function two make the link, because a single link would always take you to the same url.

    Searching the web, I found this link that better exemplifies what I'm looking for.

    So I wanted to ask if there was a way to do this with your plugin.

  4. realloc
    Member
    Plugin Author

    Posted 1 year ago #

    I believe that a theme should not have such dependency on a plugin. If you - for example - plan to create a link to a specific url in all your sites of your network and you use the same theme for all of them, you can insert something like this in your theme (I reuse the example from above):

    <a href="<?php echo network_home_url( 'link_to_somewhere' ); ?>">
    <?php _e( 'read all', 'mytheme' ); ?>
    </a>

    You have to modify 'mytheme' of course which should be the textdomain of your theme. After that you can modify the language-files of your theme and add the translation for 'Read all'.

    There is the possibility to solve your problem "quick & dirty" with the Multisite Language Switcher too:

    <?php
    
    $blog     = MslsBlogCollection::instance()->get_current_blog();
    $language = $blog->get_language();
    $link     = network_home_url( 'link_to_somewhere' );
    $text     = ( $language == 'es_ES' ? 'Spanish link' : 'English link');
    
    ?>
    <a href="<?php echo $link; ?>"><?php echo $text; ?></a>

    Cheers,
    Dennis.

  5. Carmdq
    Member
    Posted 1 year ago #

    Hi realloc, I'm not sure I'm getting your point. Or maybe I didn't explain myself correctly (English is not my mother tongue).

    I have two sites: mysite.com/en and mysite.com/es. Therefore, I have two blogs: mysite.com/en/blog and mysite.com/es/blog.

    In your example:

    <a href="<?php echo network_home_url( 'link_to_somewhere' ); ?>">
    <?php _e( 'read all', 'mytheme' ); ?>
    </a>

    I think you're telling me how to localize the phrase "Read more", but that would take me to the same link.

    What I want is that same link hardcoded in my theme, to either take me to mysite.com/en/blog or mysite.com/es/blog depending on which version/ language of the site I'm browsing.

    I will look into the other code you provided to see if that's what I'm lookink for.

    Thanks

  6. realloc
    Member
    Plugin Author

    Posted 1 year ago #

    Yes, the first solution is localizing the theme. The WordPress function network_home_url() will point to the correct blog. This can be a big advantage if the endpoint is more or less fix. For example network_home_url( 'blog' ) should point to mysite.com/en/blog or mysite.com/es/blog resp. The second "solution" is similar but (because it uses the languages directly) a little bit dirty.

  7. Carmdq
    Member
    Posted 1 year ago #

    I get it. Thanks!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.