WordPress.org

Ready to get started?Download WordPress

Forums

WP-dTree
Open to selection... (24 posts)

  1. Craig
    Member
    Posted 2 years ago #

    Hello,

    Great plug-in, thank you very much for making it!

    I have everything working how I want, with a basic main and sub categories setup.

    However I would like the tree to automatically open itself depending on what post is loaded. So for example if a user views a post in Category A, then the Category A main tree opens to display all its sub categoies. Same if a user lands on a post in Category B, etc.

    I believe this is suppose to happen by enabling the 'Open to selection' feature within the widget option???

    If so, it doesn't seem to work on mine for some reason. It will always have open the last tree that was open, or just none if its the users first visit to the site.

    I'm almost sure this worked when I first installed it, but I have tried installing the plug-in again from scratch with no change (unless settings are stored even when the plug-in is deleted?).

    Any ideas what I should be looking at?

    Many thanks!

    http://wordpress.org/extend/plugins/wp-dtree-30/

  2. ulfben
    Member
    Plugin Author

    Posted 2 years ago #

    Link?

  3. Craig
    Member
    Posted 2 years ago #

    Hi ulfben, thanks for the reply. It is a local site at the mo for testing. However I have tried on another site, and the open to selection DOES work when viewing categories, but NOT when viewing the actual post itself.

    I have replicated this on my test site also so I assume this is how it is supposed to work?

    Many thanks :)

  4. ulfben
    Member
    Plugin Author

    Posted 2 years ago #

    No that's not the way it's supposed to work. Open To Selection = opens to (and optionally highlights) the current post, category or archive, respectively.

    I need access to the site to help. But you can test if there's a difference when using permalinks or not. Make sure you're not using "force open to". Try running two types of trees; a category and an archive, see if their behaviour differs.

  5. Craig
    Member
    Posted 2 years ago #

    Ahhh I see!

    OK, I think the problem is that I have it configured to not display posts, only categories.

    I have tried turning 'list posts' on and it does open the correct tree to display the current post name.

    Ideally I would like it to open and highlight the current category that the post is in, rather than the post itself in the tree. Currently it keeps open whatever tree was open before, or if its the first visit, then all trees are closed.

    Is this option possible at all?

    If so then I could upload the site to a test domain for you to have a look at? :)

    Thanks again, your help is appreciated!

  6. ulfben
    Member
    Plugin Author

    Posted 2 years ago #

    You have discovered an edge case. I probably never tested without listing posts.

    I've added this this to my list. I'll let you know when a new release is out.

  7. ulfben
    Member
    Plugin Author

    Posted 2 years ago #

    Please try the development version here. I've added a fix for category trees without posts.

  8. KaFu
    Member
    Posted 2 years ago #

    Hi Ulf,

    I've found a related issue (still present in the dev version). In the categories widget if I open a page (which is not allocated to any category), not a post, the selection is opened up to a random category. I would have expected the tree to be collapsed instead.

    http://funk.eu
    Click on the "Contact" and "Imprint" links at the top, those are pages.

    Great work, keep it up!

    Thanks and Best Regards
    Karsten

  9. ulfben
    Member
    Plugin Author

    Posted 2 years ago #

    Interresting. We have an unintended ID-collision; your page is id 11 - correctly identified by the plugin. But the dtree JavasScript erroneously matches this with category ID '-110'.

    And I thought the negated category IDs was such a clever little hack. :D

    Could you edit wp-dtree.php so I can run a debugger on the script?

    Just change
    define('WPDT_SCRIPT', 'wp-dtree.min.js');
    to
    define('WPDT_SCRIPT', 'wp-dtree.js');

    and post here again.

  10. ulfben
    Member
    Plugin Author

    Posted 2 years ago #

    Actually, no. It's not an ID clobbering. The script simply assumes the ID passed to "openTo" is valid. If it doesn't find it in the tree it will open to the index. Your category "Coding" (ID = -110) is actually the 11nth node in the tree. Similarly; your "Imprint" (page id = 78) opens the three to index 78 (which happens to be a post on Alexa rankings).

    I need some time to set up and test a fix, but perhaps you can try it yourself?

    The offending function is wpdTree.prototype.openTo in wp-dtree.js. I believe all we need to do is remove the conditional from the lookup loop to always run it, and abort if there's no matching node.

    However; I'm not sure what side effects this might cause. Mr. Landrö probably had a reason to put the conditional there in the first place.

  11. KaFu
    Member
    Posted 2 years ago #

    Hmm, tinkered with it without success, but my JS knowledge is just fundamental to say the least :). How about adding all valid IDs to a string during creation and check for the IDs existence (with something like instr?) as the first check in the function?

  12. ulfben
    Member
    Plugin Author

    Posted 2 years ago #

    Checking for the ID is not a problem; that check is being done. But even if the ID isn't found the function progresses, treating the ID as an index. Our problem now is to find why it was written this way, or rather what side-effects it might cause to change the behaviour.

    I like your look-up solution though. Remember doing that often in ActionScript 2; the String-functions were way faster than to iterate-and-compare through an Array.

    All you need to do to test this for me is change this:

    wpdTree.prototype.openTo = function(nId, bSelect, bFirst){
    	if(!bFirst){
    		for (var n=0; n<this.adtNodes.length; n++){
    			if(this.adtNodes[n].id == nId){
    				nId=n;
    				break;
    			}
    		}
    	}
    	var cn=this.adtNodes[nId];
    	if(cn.pid==this.root.id || !cn._p) return;
    	cn._io = true;
    	cn._is = bSelect;
    	if(this.completed && cn._hc) this.nodeStatus(true, cn._ai, cn._ls);
    	if(this.completed && bSelect) this.s(cn._ai);
    	else if(bSelect) this._sn=cn._ai;
    	this.openTo(cn._p._ai, false, true);
    };

    (http://pastebin.com/Wy81h3Mm)

    To this:

    wpdTree.prototype.openTo = function(nId, bSelect, bFirst){
    	for (var n=0; n<this.adtNodes.length; n++){
    		if(this.adtNodes[n].id == nId){
    			nId=n;
    			var cn=this.adtNodes[nId];
    			if(cn.pid==this.root.id || !cn._p) return;
    			cn._io = true;
    			cn._is = bSelect;
    			if(this.completed && cn._hc) this.nodeStatus(true, cn._ai, cn._ls);
    			if(this.completed && bSelect) this.s(cn._ai);
    			else if(bSelect) this._sn=cn._ai;
    			this.openTo(cn._p._ai, false, true);
    		}
    	}
    };

    (http://pastebin.com/0Fn8uNv0)

  13. KaFu
    Member
    Posted 2 years ago #

    wp-dtree.js does not seem to be used but wp-dtree.min.js

    I changed this

    wpdTree.prototype.openTo=function(b,a,c){if(!c){for(var e=0;e<this.adtNodes.length;e++){if(this.adtNodes[e].id==b){b=e;break}}}var d=this.adtNodes[b];if(d.pid==this.root.id||!d._p){return}d._io=true;d._is=a;if(this.completed&&d._hc){this.nodeStatus(true,d._ai,d._ls)}if(this.completed&&a){this.s(d._ai)}else{if(a){this._sn=d._ai}}this.openTo(d._p._ai,false,true)};

    to this

    wpdTree.prototype.openTo=function(b,a,c){for(var e=0;e<this.adtNodes.length;e++){if(this.adtNodes[e].id==b){b=e;var d=this.adtNodes[b];if(d.pid==this.root.id||!d._p){return}d._io=true;d._is=a;if(this.completed&&d._hc){this.nodeStatus(true,d._ai,d._ls)}if(this.completed&&a){this.s(d._ai)}else{if(a){this._sn=d._ai}}this.openTo(d._p._ai,false,true)}}};

    but that seems to break the opento function and nothing is opened at all.

  14. ulfben
    Member
    Plugin Author

    Posted 2 years ago #

    wp-dtree.js does not seem to be used but wp-dtree.min.js [...]

    ... so either read what I've said, or - you know - copy the content of one into the other? Whichever makes you happy.

  15. KaFu
    Member
    Posted 2 years ago #

    The code above should be the minified version of what you've posted. Nevertheless I copied your original code to wp-dtree.js and replaced the wp-dtree.min.js on my server with this new version... exactly the same result as for my minified version above, opento does not seem to work at all.

  16. ulfben
    Member
    Plugin Author

    Posted 2 years ago #

    Check. I need to set up a test environment and sort this out. You'll be notified when a new version is out.

  17. KaFu
    Member
    Posted 2 years ago #

    Thanks for taking a deeper look :)...

  18. engelle
    Member
    Posted 2 years ago #

    i'm having a different issue about the same thing, i've noticed that when i select an individual/single post from a category, it highlights the first alphabetical category that it is part of, not the category it was selected from. how can i fix this? what variables might be passing this info?

    my menu has only category names, no individual post listings.

  19. ulfben
    Member
    Plugin Author

    Posted 2 years ago #

    Link?

  20. engelle
    Member
    Posted 2 years ago #

    sorry no, it's all internal right now. is what i'm seeing an anomaly?

  21. ulfben
    Member
    Plugin Author

    Posted 2 years ago #

    Probably.

  22. engelle
    Member
    Posted 2 years ago #

    actually, the alphabetical jump seems to be occuring in your development version but not the prior one.

    the prior one is acting different for me than the original poster. it's inconsistent and i can't figure out what the trigger is, but with some of the sub or sub sub or sub sub sub categories, it'll highlight the upper most parent instead. all sub/parent categories are assigned but it still jumps to the top (i've noticed that if all the parent categories aren't selected then it will definitely open to the topmost parent category).

  23. ulfben
    Member
    Plugin Author

    Posted 2 years ago #

    I don't debug by divination. I need access to the site (preferably running non-minified scripts).

  24. engelle
    Member
    Posted 2 years ago #

    Here's another thing. I noticed that when I had a pages tree and a categories tree together, that the pages wouldn't automatically close branches in the categories. That's fine.

    So I put in a little code for some value swapping of the "showselection" parameter and had it working great. But now... not working. I'm not sure if even doing what I did should fundamentally work, but it was doing it for a couple weeks. Any idea what happened?

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic