This is searchable archive of our old support forums, which operated from 2012 - 2016. To find out how to get support for your current theme, please visit our support page.

Reply To: WPML issues with custom homepage layouts

#2471
Jason Bobich
Keymaster

All right, so I’m going to do my best to address these issues in an order that makes sense with solutions for the various items sort of going together. All issues that I’m trying to reproduce and find solutions for are being done on my live server here (opposed to locally as I normally would): http://themeblvd.com/demo/wpml — Using Swagger v1.1.5, WPML v2.6.3, Theme Blvd WPML Bridge v1.1.1, WordPress v3.5

WPML Bridge Plugin

Keep in mind that my WPML Bridge plugin really doesn’t do a whole lot in modifying anything that has to do with WPML. The bulk of it essentially just uses WPML languages to designate a Theme Options page for each language. And then on the front-end of the site, it gives you some custom flag switchers you can use completely separate from WPML’s default switchers.

Language switcher behavior

2. The WPML frontend language switcher does not point to the correct content of the other languages. For example when I am on a Page, the WPML language switcher points to a category.

I can confirm this happens on my end, as well. The reason is because the theme uses query_posts() on paginated post lists and paginated post grids and then does not use wp_reset_query() afterwards as it should. This causes issues for WPML. This is something that was addressed and fixed a while back for the next update (which doesn’t help you at the moment).

For example, in your case, we use query_posts('category_name=whatever'), and now WPML thinks we’re on a category archive page when it gets to rendering the switcher.

Let’s first discuss options for this Chapters page and then get to a solution to the issue of the switcher. — I noticed you guys have a custom layout with a paginated post list setup. First off, out of the three ways you could have constructed this page, it’s probably the least efficient way in terms of resources it’s going to take to load. I know you, Piet, have never used my themes, so I just want you to be aware of your options here to accomplish a page displaying a paginated post list. Here are your ways in order with #1 being the most efficient.

  1. Category Archives: Link directly to the WordPress category archive page. — In doing this, there’s no query_posts, so you shouldn’t have any issues with the WPML language switcher widget.
  2. Post List page template: Create a page and apply the “Post List” page template. This is what I’ve done on my demo site’s “Blog” page. On each language variation of that page I added a custom field called “category_name” with value of the slug that language’s “blog” category. See here for custom fields you can use with the page template.
  3. Custom Layout: Create a custom layout and a put a paginated post list element in it. Apply that custom layout to a static page.

And from your Child theme’s functions.php here is how you can reset query_posts to fix the language switcher issue with #2 and #3. Let me know if this doesn’t work. — It’s a little hacky and won’t be needed in Swagger v1.2, but basically we’re just hooking into the sidebar function before the actual sidebar does to reset the query.

add_action( 'themeblvd_sidebars', 'wp_reset_query', 9 );

Selecting categories in custom layout.

1b. when using the WPML backend language switcher to change the language to for example German, then the same happens as above, but for all languages, so the in English it is impossible to choose the correct English category.

This is actually not the case for me. See screenshot: http://www.uploadblvd.com/uploads/image_50f215452320e.png

However, either way, I will admit this is probably not ideal with working with WPML because you’d have to ensure that you never opened and saved a layout of one language while under another language. This could get messy in the long run.

1a. the custom layouts per language seem to work well, BUT when choosing the Post List element then the Categories of English (default language) show up for both German and Swedish (the secondary languages).

Keep in mind that creating these different custom layouts is not built around WPML in any way. We’re just using the WPML Bridge plugin to take this layout system and then be able to apply it to different languages from the Theme Options page.

So a workaround here would be to use the “Custom Query” option when editing your custom layouts’ Post List elements. When you put anything in the custom query option it will override any of the other query-type user options before it. So basically by going to each language and manually putting in a call to the category for that language, you’ll be ensuring that the user can’t open up that layout from the wrong language and unintentionally mess up the category selections.

Future scheduled posts

The theme does not respect scheduled posts (to be published at a date in the future) for the secondary languages.

Honestly, this in itself doesn’t quite make sense, as when you execute any query, this should already be the case by default. In other words, you shouldn’t ever have to factor into your query to exclude future posts. This is default state of any query from the beginning. I can only think there’s something specific about your site that you could possibly be overlooking? Maybe some kind of other plugin that does something with scheduled posts?

Maybe you can play around a little more with this with the different ways of setting up these content the theme offers that I’ve explained and see if you can narrow down how this issue arises? Here’s what I’ve done to try and reproduce the issue and everything is working for me.

  1. I have a category called “portfolio” of posts. Every post has been translated into English, French, and German, and applied to its corresponding “portfolio” category of its given language.
  2. I’ve setup a static page with a Post List page template applied. I’ve created a version of this page in English, French, and German.
  3. For each language version of this page, I’ve include the corresponding category of posts by adding a custom field called “category_name” with the value of the category slug for each. See screenshot.
  4. I created a post called “Future Post” translated into all languages, in which I scheduled to be published next year.

Here’s a screenshot of how all of these included posts are setup for my “Portfolio” category: http://www.uploadblvd.com/uploads/image_50f221de795be.png

English: http://themeblvd.com/demo/wpml/post-list/
French: http://themeblvd.com/demo/wpml/post-list/?lang=fr
German: http://themeblvd.com/demo/wpml/post-list/?lang=de

You can see that on none of the languages show the “Future Post” at the top.

Note: Just a random tidbit, on these pages I’m linking to with the Post List, you’ll notice that the WPML Language Selector widget in the sidebar does work, and that is only because I’ve applied the fix mentioned previously.