Site logo

Archived topic

polylang with choosing posts in linked categories

9 replies · Started by Hung on October 31, 2021

Viewing posts 1–10 of 10

I set up an element for preload CSS, and chose Ignore Languages. The CSS is applied for all posts in categories A & B, while A is written in English, and B is written in Vietnamese, which is translated from A.

The problem is that in the display rule, it's showing only one category, either A or B, depends on the language of the element.

Do I still need to setup two elements for two languages? Or am I missing setting somewhere?

Thanks.

Hi there,

Do I still need to setup two elements for two languages? Or am I missing setting somewhere?

You may have to do that. Display rule location is basically your if/else condition on how it will display.

But it's strange that it's not showing on both if you set it to ignore language. Ignoring the language should mean you're basically setting it as a global, meaning all languages, but this I may be wrong about that.

Can you share the exact settings of the element you're working on?

Well... there is not much settings I guess. Creating a new element straight away, like in the short video I attached. As you can see, the problem seems happening with post categories only. All the pages are visible there, both English and Vietnamese.

Then even choosing Ignore Languages, if there is only elements in English, the results are happening with English posts, not Vietnamese and vice versa.

Strange. I just tested the latest version of polylang (free) w/ the latest version of GP + GP premium and ignore language option seems to work.

Can you provide the preload code and links to a sample page (for 2 different languages) where the preloaded CSS are supposed to load?

To check if perhaps the selectors are just not applicable. Let us know. :D

Hi.

Here is an example, even with pages.

1. Double checked to access directly with browser http://IP-address/wp-content/themes/mytheme/css/news.css. It's showing the CSS content without any problem

2. Creating a hook element with Vietnamese language.

<link rel="preload" href="http://IP-address/wp-content/themes/mytheme/css/news.css" as="style" onload="this.rel='stylesheet'">

3. Display rule:
- Pages - Tintuc (in Vietnamese)
- checked Ignore Languages

Now, view the Tintuc page, the news.css is loaded.But its translated page in English - News hasn't the news.css file.

4. Changing the display rule:
- Post categories - Tintuc
- checked Ignore Languages

Again, the posts in Tintuc is loading news.css just fine. But news.css doesn't appeared in English posts.

I am also using the latest Polylang free version 3.1.2, GP Premium 2.1.1 + GP 3.1.0.

Since it's working on my end then it's likely a setting on a site or a display rule issue on the site in question.

Any chance you can provide us temporary backend access to the site you're working on? To check its element settings and the structure of the posts and taxonomies.

Sure. I included the login info and some links for testing. Thanks.

Ah I see now. There was an issue w/ the previous test I've made. My bad.

In this case you really must create a new Header Element on the selected language - https://share.getcloudapp.com/DOu6DgkJ

Make sure you're in VIE list when you're making a Header Element for the Vietnamese pages and ENG for the English pages.

This is because the Display rule location sees the translations as completely different taxonomies. You can actually see that the category term and it's translated term has 2 different IDs. (News has ID of 8, Tin tuc has ID of 1) This means, while the 2 are related by translation, they're technically 2 different things.

So, the answer for my original question is no, right? :)

I haven't checked into the GP Premium and Polylang code yet, but in my thought, if I checked "Ignore Languages", then the code can do some extra steps:
1. get list of all languages.
2. get translated item ID in each language from the chosen item ID, either pages, posts or categories. The chosen item ID is from the Display rule.
3. apply the rest of functions like now, with each translated item ID.

Is that possible?

The answer to "Do I still need to setup two elements for two languages? Or am I missing setting somewhere?" is yes you'll have to create an element for each language.

This is because the Element's display rule location can only list the taxonomy terms of the language you've selected here - on the selected language – https://share.getcloudapp.com/DOu6DgkJ or within the block editor (after refresh, the display rule location options change)

1. get list of all languages.
2. get translated item ID in each language from the chosen item ID, either pages, posts or categories. The chosen item ID is from the Display rule.
3. apply the rest of functions like now, with each translated item ID.

This is possible with generate_element_display filter. https://docs.generatepress.com/article/generate_element_display/

And then do a condition like this:

add_filter( 'generate_element_display', function( $display, $element_id ) {
    if ( 123 === $element_id && is_category() ) {
        $display = true;
    }

    return $display;
}, 10, 2 );

Where 123 is the ID of the Element you're trying to display. The is_category() part basically tells the filter to display the element on all category archive pages but you can specify the categories by adding an array. Example: is_category( array(1,2,3,4) )

This archived topic is closed to new replies.