Site logo

[Resolved] Display rules in Elements and Polylang

Home Forums Support [Resolved] Display rules in Elements and Polylang

Home Forums Support Display rules in Elements and Polylang

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #1811486
    Bernhard

    Hello,
    I want to report a little problem with the display rules in Elements.
    When I check “ignore languages” I can select post and pages in all languages and this is correct.

    The problem is with post categories, there I can only select categories in the defined language.

    My workaround is for now to duplicate the element for all languages and select then the category in each language. But this blows up the number of elements and probably you can do a fix in a future version.

    The heaven would be to define the category only once, as it is in WP Show Posts. There I select the category only in one language and it works for all.

    #1812698
    Elvin
    Staff
    Customer Support

    Hi Bernhard,

    You can bypass the Element’s settings in UI by using this filter: generate_element_display

    Example: displaying Element id 1234 on English UK language (en_GB) for posts/pages under category slug “movies”.

    add_filter( 'generate_element_display', function( $display, $element_id ) {
        if (1234 === $element_id && get_locale() == 'en_GB' && in_category('movies')) {
            $display = true;
        }
    
        return $display;
    }, 10, 2 );
    #1814289
    Bernhard

    Hi Elvin,
    I’m not sure if it makes a big difference to duplicate the elements for each language or to add the code for each language, category and element.

    Do you have a place for change requests?

    Thank you.

    #1815523
    Elvin
    Staff
    Customer Support

    Hi Elvin,
    I’m not sure if it makes a big difference to duplicate the elements for each language or to add the code for each language, category and element.

    If we can get the proper language condition, it should work. I’m not exactly sure what polylang is using but perhaps this is the right one https://gist.github.com/beovulf/5a1c26bec2eadd7bde413fc81df31771

    Do you have a place for change requests?

    Do you mean feature request? We can log it this topic as a feature request if you want.

    #1819231
    Bernhard

    Hi Elvin,

    This is my feature request:

    – if in the Elements display rules “ignore languages” is checked
    – a display rule defined in one language (or in alternative defined in the default language) shall be valid for all languages

    What I mean: If in a display rule is selected a page, post, category etc. in one language, this shall apply to the same page, post, category etc. in all languages

    If you define it for WPML it will work also in Polylang.

    Thank you 🙂

    #1820176
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    That’s strange, as that is how the Ignore Languages option should work. It should make it so an Element displays based on its Display Rules regardless of the current language that’s set.

    Any chance you can explain a bit more or link to an example or two so I can get a clearer picture of what’s going wrong?

    Let me know 🙂

    #1820661
    Bernhard

    Hi Tom,
    I have added a temporary login to my staging site.

    Actually it works as follows, when ignore languages is checked:
    – if the display rule is “front page”, it works for the frontpage in all languages
    – if the display rule is for a post or a page, I have to select the post or page in every language ( I tested in the past and I saw that the rule works only with the selected post and not with the same post in the other languages ). It would be fine if it would be only necessary to select posts/pages only in one language.
    – if the display rule is for a post category, the categories are only shown for the language which is flagged in the polylang window ( I tested this also and found, that the rule works only with the selected category and not with the same categories in other languages )

    In the Elements main page, you can see that I had to create Tiqets rules for all 3 languages, because I wanted to address post categories and this was not possible otherwise.

    I prepared a little screen record, probably this helps to explain it better.

    In WP Show Posts it works correct. There, it is enough to select a category in one language. In the example, only the category rom-praktische-tipps is checked, the same categories in the other languages are unchecked (rome-practical-tips, roma-consigli-pratici), but the list works in all languages.

    #1822261
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Sorry for the delay there – language-related issues like this are always difficult to debug.

    if the display rule is for a post or a page, I have to select the post or page in every language

    If you un-check the “Ignore languages” field – is this issue the same?

    #1822424
    Bernhard

    Hi Tom,
    If I un-check the “Ignore languages” field, the display rule works only with the flagged language and not with the other languages.

    I tested the following:

    “Ignore languages” un-checked + page selected in flagged language -> Display rule applies to the selected page in the flagged language and not to the other languages

    “Ignore languages” un-checked + page selected in flagged language + other languages -> Display rule applies to the selected page in the flagged language and not to the other languages Note: usually Polylang would only show posts and pages in the flagged language for selection

    “Ignore languages” checked + page selected in flagged language -> Display rule applies to the selected page in the flagged language and not to the other languages

    “Ignore languages” checked + page selected in a not flagged language -> Display rule applies to the selected page in the not flagged language and not to the other languages

    “Ignore languages” checked + page selected in flagged language + other languages -> Display rule applies to the selected page in all selected language versions

    #1823603
    Tom
    Lead Developer
    Lead Developer

    Just to rewind back a little, this main issue here is with categories, right? Pages are working fine?

    The only thing I can think of is that Polylang has formed some sort of relationship between the same page in different languages that allow the one Display Rule to work. I wonder if that same relationship is formed between categories? How exactly are you building different categories for different languages?

    #1823760
    Bernhard

    Hi Tom,

    this main issue here is with categories

    yes

    Pages are working fine

    it’s ok, but it would be better if it would be enough to choose posts and pages only in one language

    Polylang has formed some sort of relationship between the same page in different languages that allow the one Display Rule to work. I wonder if that same relationship is formed between categories?

    Yes. Example, if I select a category for a post in one language these categories are automatically selected for the same post in all languages.

    The categories in the different languages are linked in the same way as posts and pages. Link to categories img1 img2

    #1824846
    Tom
    Lead Developer
    Lead Developer

    I’m far from a multilingual expert, but my guess here is that Polylang is simply changing the posts in the category depending on your language – it’s not changing the actual category page. So, the Display Rules targeting the category would apply to all languages (as it never changes, only the posts do).

    More advanced Display Rules like this are where our filters come into play, as Elvin pointed out here: https://generatepress.com/forums/topic/display-rules-in-elements-and-polylang/#post-1812698

    It would definitely be cool if it were possible to select the language in the Display Rules itself. I’ll add that to our board as something to look into.

    #1824930
    Bernhard

    Hi Tom,
    I am a simple user. But as far as I can observe Polylang’s behavior, Polylang seems to consider category pages just like posts and pages. The category pages of different languages seem to be connected just like posts and pages in different languages.
    Perhaps it’s a matter of hierarchy, where Elements’ display rules intervene. But being able to select the categories in each language in the display rules would certainly be a possible solution.
    I must say, I discovered the problem with the categories by accident. Usually I apply the display rules only to posts and pages. This was the first time I wanted to address a category.
    I am sure you will find a good solution. 🙂

    #1826033
    Tom
    Lead Developer
    Lead Developer

    I’ll play with it and hopefully come up with a good solution. Thanks! 🙂

Viewing 14 posts - 1 through 14 (of 14 total)
  • You must be logged in to reply to this topic.