without language codes to permalink may causes 404

After activating SimpleTagging plugin I faced some problem. To avoid that I disabled the Gengo’s feature `Gengo should append language codes to permalinks automatically.’.

Days later I noticed a WordPress’ strange behavior.

I have pages having translations and when I clicked a link to the another language’s page then I saw a `404 Error’ page.

That’s strange.

Went further investigation I found a bad smelling code in the `locale’ filter.

Index: gengo.php
===================================================================
--- gengo.php   (revision 80)
+++ gengo.php   (working copy)
@@ -1222,7 +1222,7 @@
  } else {
    $value = $parser->query_vars['pagename'];
    if (($position = strpos($parser->query_vars['pagename'], '/')) !== false) {
-     $value = substr($value, $position + 1);
+     $value = substr($value, 0, $position);
    }
    $where = "p.post_name = '$value'";
    $join = "INNER JOIN $wpdb->posts AS p ON p.ID = p2l.post_id";

One of the pair pages I faced 404 error have 3 depth hierarchy.

software/wordpress-plugins/l10n-helper.html    <English>
software_ja/wordpress-plugins/l10n-helper.html <Japanese>

Before modification the value of $value was set as:

wordpress-plugins/l10n-helper.html <English>
wordpress-plugins/l10n-helper.html <Japanese>

$wpdb->posts.post_name only have a post name for 1 depth of hierarchy but the code got of 2 depth. And the code does not seem to care of WordPress feature that it allows to have same post name among pages while the top of ancestors of those page’s are not same.

I fixed the code to obtain the first part of uri.

6件のコメント

  • At 2007.10.31 22:21, tino said:

    Oh my God… you have no idea how long I was looking for help connected with this problem that you solved.
    Thank you, thank you and one more time thank you!

    And by the way maybe you will be able to help me with one more problem connected with gengo.

    I have my website in three languages: english, polish and german.
    I have “Gengo should append language codes to permalinks automatically.” option on.
    And everything is ok, I mean my english version of the website is:
    http://www.something.com/en/
    Polish version:
    http://www.something.com/pl/
    German version
    http://www.something.com/de/

    What I want is to have english version without /en/ at all or at least without /en/ on the first page, so that english version will be http://www.something.com

    If somebady will write http://www.something.com it will always open english version. If somebady will write http://www.something.com/pl/ it will open polish wersion and so on.

    What do you thing? I hope you understand me.

    Regards,
    Tino

    • At 2007.11.01 10:32, reedom said:

      Hi tino,

      I think Gengo already has such option for you.

      Look for`When reader visits for the first time:’ and
      select `Show posts in ~’ to ‘English’.

      Doesn’t it work for you?

      • At 2007.11.05 22:06, tino said:

        No it’s not what I’m looking for. I now that website can start in english but if “Gengo should append language codes to permalinks automatically.” would be on I will have:
        http://www.something.com/en/
        http://www.something.com/pl/
        http://www.something.com/de/

        If the option “Gengo should append language codes to permalinks automatically.” would be off I will have:
        http://www.something.com/ for every plish, german ang english

        An I wont to have:
        http://www.something.com/ – this will open only english always
        http://www.something.com/pl/
        http://www.something.com/de/

        Tino

        • At 2007.11.05 22:10, tino said:

          So I want to have pages in English without /en/ at the end but Polish and German should have /pl/ /de/ at the end.

          Sorry for my mistakes in previous comment.

          • At 2007.11.07 20:14, tino said:

            Or maybe it is posible to do only one thing. Change option ““Gengo should append language codes to permalinks automatically.” that it will add language codes everywhere besides the main domain. So for http://www.something.com/ there will be no language code. But for every subpage there will be a language code.

            • At 2008.01.22 01:46, digitalbase said:

              This code was not working for me

              (Required)
              (Required, will not be published)