WordPress.org

Ready to get started?Download WordPress

Forums

Dynamic Widgets
[resolved] Dynamic Widgets, WPML, submenus on sidebars (11 posts)

  1. Gwyneth Llewelyn
    Member
    Posted 3 years ago #

    Ok, I'm pushing the limits with Dynamic Widgets here, so bear with me for a moment...

    I installed Dynamic Widgets for its support of WPML (multilingual WP — works like a charm!). Now I have a website for a customer on three languages. The silly customer has some 200 categories and as much pages all scattered around the menus, so here is what they want: a contextual submenu for each area. So every time WP is on an area, it shows a different menu specific for that area.

    I'm deliberately talking about "areas" because these are "categories" in some cases, "pages" in others. It's a huge mix.

    Here is how it works with WP 3.1 and Dynamic Widgets: create a sidebar menu. For each area, there is one "contextual list of selections", so I create a different menu. Then tell that menu that it should only show up for certain categories and/or pages. That's it. The sidebars get dozens (perhaps hundreds, when I'm finished) of menus on sidebar widgets, but only one is active for each category or page (I'd prefer a more automated system, but it's hard to do when one has a mix of pages and categories throughout the website...). It works flawlessly for the main language.

    There is just one problem. Dynamic Widgets just shows me the categories and pages on the main language, not on the translations. This is actually correct: when switching languages, I wish to get the translated menu, which is automatically linked via WPML, so it makes sense only to show the "main" language to make the selection.

    The problem is that the translated site will never see the correct menu. In fact, it will never match to anything. I think this might be a bug or I'm just incorrectly configuring things...

    Any clues on how to make this complex setup work would be appreciated!

    http://wordpress.org/extend/plugins/dynamic-widgets/

  2. Qurl
    Member
    Plugin Author

    Posted 3 years ago #

    So, basicly if I understand you correct a translated widget is not showing up on a translated site, but it does show up on the main language.

    Are the main language widget and the translated widget linked to eachother in WPML? In other words, the main language widget is replaced by WPML with the translated widget when switching over languages? This all is done without any rules set for the widget by Dynamic Widgets.

  3. Gwyneth Llewelyn
    Member
    Posted 3 years ago #

    Sort of. Let me try to give an example with numbers to see if it makes more sense that way.

    Let's assume that my site has the following categories in the main language:

    1 - No category
    2 - News
    3 - Photos
    4 - Archive

    There is a set of translations in two additional languages. So, category 5 is, say, "no category" in French, and so forth; category 9 is "no category" in Japanese.

    These are all linked in WPML, e.g.

    1 (main) -> 5 (translated in French), 9 (translated in Japanese)
    2 (main) -> 6 (translated in French), 10 (translated in Japanese)
    3 (main) -> 7 (translated in French), 11 (translated in Japanese)
    4 (main) -> 8 (translated in French), 12 (translated in Japanese)

    Now, what I want to do is to display a widget (and its translated content) ONLY when the user is currently on category 2 (or, if they are viewing it in French, cat 6; if they're Japanese, they'll be on cat 10).

    With Dynamic Widgets, I can only select the first 4 categories, i.e. what I've listed above. This is correct for Dynamic Widgets: it understands correctly how the translated categories are linked together, and so just needs to display the "main" ones.

    The widget actually contains a contextual menu, i.e. it pulls up a menu specific for that category (configured under the normal WP3.+ menu setup, and with associated menus in the two other languages). So, when the user is on category 2, the widget gets correctly displayed, and it shows the appropriate menu for the main language. All other categories (or pages, and single posts outside that category) never display the widget, as expected: Dynamic Widgets does that well and without flaws.

    When, however, the user is on category 6 (i.e. viewing the site in French), neither the widget, nor the menu inside it, are shown. So I suspect that somehow Dynamic Widgets has "lost" the relationship between 2 <-> 6 <-> 10 for some reason. A possible workaround would be to specifically make the widget appear on categories 2, 6, and 10, by selecting them manually (it would be a pain to keep them in sync with the translations, but, well, doable). But that is not possible, since Dynamic Widget's configuration for the widget never shows the categories 5-12 for selection, but just 1-4.

    To make sure that the problem is not with the menus, I just created a simple text widget. The same problem arises.

    The only thing that I might be missing here is that somehow Dynamic Widgets expects a textual relationship between the categories, e.g. if the main category is "News" and its URL bit is "news", then the translated version in French has to be news-fr and the one in Japanese news-jp. If that's the case, it would explain why categories 6 and 10 are not "seen" by Dynamic Widgets to be linked to category 2...

  4. Qurl
    Member
    Plugin Author

    Posted 3 years ago #

    Let me first answer your question... No, Dynamic Widgets does not look to text, it uses the ID. When not on the main language, DW detects this and retrieves the main ID via a WPML function. With the main ID known, it applies the rules set.

    What I'm missing in your story is if the menu's for the different languages are also linked to eachother. So let's say
    Main Menu-A --> French Menu-A --> Japanese Menu-A

    I just tried myself with a widget by default off and only on a certain catagory and that worked without any problem in every language.

    What happens with the test text widget without any DW rule applied to it (so made static)? Does it show up in every language?

  5. Gwyneth Llewelyn
    Member
    Posted 3 years ago #

    Qurl, thanks so much for getting back to this issue, and so quickly too :) I see that Dynamic Widgets has a great community and makes me far more happy to be using it, knowing that so many helpful people are willing to spend their time answering questions — a very heartfelt thanks!

    Ok, it's good to know that it only uses the ID (which makes a lot of sense, really). So, one problem less to worry about! I will have to try out to see if by some reason WPML "lost" the connection between the languages for that specific category, and that would explain everything.

    The menus are linked together as you say, yes. But since I also suspected the menus, I did use a plain text widget. When DW is set to "static" it obviously shows up in every language; once it's set to dynamically appear only for certain categories, it shows up perfectly on the "main" language, but not on the translations.

    Still, this seems to be a bit more complex. Sometimes, when switching from one language to another, the widget will remain! But a page refresh (in that language) will make it disappear. Since I have no cache on — except what WP inherently caches, or, who knows, WPML might do some caching at well — this behaviour is strange. So something weird is happening.

    What I'm also going to try out is a fresh set of correlated categories, a new set of widgets and menus and so forth, and getting the WP site to emit the current category it thinks it is in. What I suspect now is that DW is not to blame, but that WPML, for some reason, has "broken" language connections in some categories, even though the WP backoffice shows those correctly. This particular site has lots of categories! (160 was my last count) During the setup, this often meant categories that have changed location in the hierarchy, were deleted and recreated again, renamed, and so forth. Perhaps WPML has not updated parts of its database tables correctly for some reason, and this would explain why DW is having difficulties.

    Thanks for the outstanding help so far!

  6. Qurl
    Member
    Plugin Author

    Posted 3 years ago #

    Just to make sure - actually because I just found a bug in Dynamic Widgets which is WPML related, not (always) retrieving the main ID - Are you using Custom Post Types?

    It's strange tho a widget sometimes appears and the other time not. Maybe the theme is having some problems with WPML? I can send you a slightly modified dynamic-widgets.php which puts DW into debugging mode. If I'm able to visit the site, you can pick out a category and widget which behaves incorrectly. I can probably analyze what's going on in a DW perspective.

  7. Gwyneth Llewelyn
    Member
    Posted 3 years ago #

    No, I'm not using Custom Post Types.

    The "weirdness" about having the widgets sometimes appearing, and sometimes not, is possibly related to WP Super Cache: I had it installed, but inactive. Apparently, even an inactive WP Super Cache does some caching! Oh well. Now I've un-installed it, to make sure it doesn't interfere with the testing.

    The theme is a pretty standard (for now) since I'm just working on the structure while waiting for the designer... I'd be glad to send you a link to it in private (since it's not open to the public yet).

    Finally, I believe that the problem really has to be with WPML. I've done a test on a different category and with a different widget on a different area of the site, and it seems to be working as expected. I'll do a few more tests with other categories. Possibly I have been extremely unlucky with one category that happened to be broken :-( Or perhaps it's subcategories that are giving problems... I don't know, but I'll continue to test it. I suddenly realised that doing the whole site without DW will take eons :-) so I better put a lot of effort in figuring out this issue...

  8. Qurl
    Member
    Plugin Author

    Posted 3 years ago #

    Ok, great you're not using that... or maybe not as the mystery hasn't be solved fully. You can mail me via: jacco at qurl dot nl

  9. Gwyneth Llewelyn
    Member
    Posted 3 years ago #

    Luckily for me, the client agreed to postpone the multiple translations, so I just focused on one, assuming that I could get back to it later, in time. There are lots and lots of dynamic menus (menus embedded into dynamic widgets) to create for the 160+ categories, so I pretty much ignored the WPML issue and went ahead...

    Today, while adding a new plugin, I suddenly realised that all menus stopped working. To be more precise, all category links returned an error page. Well... not all. A few are pointing to the wrong category instead, or, although the link is explicitly for the main page, it points to a different language instead, all of a sudden (and the translated page has more wrong category links, sometimes pointing to another different language!). This is happening automatically: I checked and double-checked all link entries on the menus. They are all correct. Apache is getting the correct category link, too. But something is hooked on the "category" filter and making DW play havoc...

    Well, the usual solution in this case is to delete plugins until things start working again. I immediately suspected that my theme template (built upon the Carrington framework) was the culprit, so I've changed it. The error persisted. Then I turned WPML off. Still no luck! Then I started to eliminate plugins, one by one. Fortunately, I was lucky, it seems that after deleting two redundant XML Sitemap Generators, Dynamic Widgets started working again. Whew! I have hundreds of hours getting this to work, and I didn't realise I would be so dependent on Dynamic Widgets for this site!...

    My conclusion: DW is very, very dependent on the order plugins are installed and removed! This might account for my problems with getting the menus working properly in different languages. As said, I'll focus now just on the main language, and postpone a fix for later. Apparently, errors mostly happen with other plugins interfering with DW — mostly, pre-3.X plugins. So I just have to be careful!

    I'll add a few suggestions on other threads. I think this one can be closed for now. Thanks for the incredible support :) A small donation is on the way.

  10. Qurl
    Member
    Plugin Author

    Posted 3 years ago #

    I refuse to believe DW is picky about the order of plugins installed. I'm more suspecting the Carrington framework in combination with (a few) other things. Mainly because of the enormous flexible way the Carrington framework works. I'm going to have a look to it. Maybe I can find out a bit more.

    Thanks for the donation! I just received it. :)

  11. Gwyneth Llewelyn
    Member
    Posted 3 years ago #

    Ok, I think that the issue is not related to Dynamic Widgets, and just marginally related to WPML, but it's really my fault.

    After checking the forums for WPML, there were a lot of explanations on how WPML binds categories in different languages together: it adds a two-letter code for the country on a special table. These get stripped out when showing them on the frontend and are supposed to be visible just at the database level.

    Now I had some bad luck with one "intermediate" version of WPML (the issue has been fixed in the mean time): for some reason, a few categories were displayed with the -fr or -en etc. two-letter codes, and it just looked awful. So I tried very hard to get rid of those category names, and eventually — because of some lack of error-checking — I succeeded doing so from WP's admin panel, which shouldn't be possible. But it was. Doing that broke the relation between the category names and the multiple languages.

    Since I did not change anything at the database level, the relationship between the languages is still there. WPML is correctly reporting the right categories to DW. DW is just using what WPML feeds it. On the WPML tables, the relationship is still there and correct. But when spewing out slugs for the URLs, WPML can only emit my illegitimately-modified category names, and this wreaks havoc on the translations.

    I'm not yet 100% sure of this, but, if so, I'm the one to blame :) DW is fine; even WPML is working as it should; it's just that I was forcing WPML to accept things it shouldn't. Unfortunately for me, I had started with the most important categories first, and these are now the ones that are broken. This mostly means going through the database and looking at the table entries and see if I can manually fix things as WPML expects them to be, and then see if DW will be happy with that and work as expected, too.

    The saga continues... stay tuned to a few more episodes... in the mean time, I'd provisorily say that it's all my fault, and that the errors I get are next-to-impossible to reproduce, since the latest WPML upgrades are supposed not to allow users to change the translated category names so easily from the WP admin panel :)

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic