We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22676
    • 12 Posts
    Hi,

    Just want to know if it’s possible with Modx to generate correct navigation for categories/subcategories through the admin. I played with the script only a little bit and what I see with the default demo version is that the script seems to suffer from the same problems as the current script I’m using: getting the navigation to display like you want. I need to create literally thousands of categories and I certainly don’t want them ALL showing up on every page. So is there a way to simply (SIMPLY being the key word here) make it so that 1.)categories hide their subcategories till clicked, and (2) when you click on subcategories have them display their parent structure when pages are loaded? ’Hope I’ve been clear on this, what I’m looking for.

    Thank you.
    • I’m not aware of a default menu builder that does this, but it sounds like it’d be relatively easy to build.
        Ryan Thrash, MODX Co-Founder
        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
        • 18397
        • 3,250 Posts
        I believe this snippet will do the trick:

        http://modxcms.com/forums/index.php/topic,702.0.html
          • 22676
          • 12 Posts
          Thanks for the replies, mates. I probably won’t use the snippet since I don’t want to be dependent on third-party code that might become obsolete if the developer stops work on it and Modx is updated. It’s the same situation I have now with the script I’m currently using. Interesting how these guys give you all these great advanced tools to work with but seem to often overlook the basic stuff. Ah well, the search goes on.... smiley
            • 18397
            • 3,250 Posts
            Well, that snippet is by Adam who is part of our core team. Additionally, we’ll help with just about any snippet here so no worries about support. Also, we try to not ignore existing snippets with new releases so its doubtfull it would become obsolute anytime soon.
              • 22676
              • 12 Posts
              Thanks Mark, that’s encouraging! I’ll give it another go then and try the snippet. Hopefully it’ll suffice for all the categories I need to create. I think the directory script I’ve been using has kinda spoiled me when it comes to category creation, it created the 10,000+ categories I made so easily and beautifully that I just took it for granted, figured it would be a staple of most cms scripts out there.

              Anyway, thanks again! smiley
                • 22676
                • 12 Posts
                Okay the snippet seems to work fine except for one annoying thing: an extra nav icon that precedes the category list on the first page and that’s inserted between the last couple of categories listed on all other pages. I’m sure it’s something incredibly simple but I’m just not seeing it at the moment. I know it’s not the css because I tried the snippet in a test template that had no other code or css reference and the same problem was occurring. Is it just one too many breaks or something my editor is making or something in the snippet code itself that needs to be edited? This is the snippet code exactly as I’m using it:

                // PSUEDO CONSTANTS //
                $page_fields = ’id,pagetitle,description,published,deleted,isfolder, hidemenu’;

                // INITIALIZE VARIABLES //
                $parents = array();
                if(!$doc_id) { $doc_id = $modx->documentIdentifier; } // If doc_id not set use the current doc
                $page = $modx->getPageInfo($doc_id,0,$page_fields);

                // If the current page is a folder add it to the parent array
                if($page[’isfolder’]) {
                $parents[$page[’id’]] = $page;
                }

                // Loop through each parent to the current page
                // if it’s published, not deleted and show in menu is set, add it to the parent array
                while($page = $modx->getParent($page[’id’],0,$page_fields)) {
                if($page[’published’] && !$page[’deleted’] && !$page[’hidemenu’]) {
                $parents[$page[’id’]] = $page;
                }
                }

                // Reverse the array of parents so we can start at the top instead of the bottom
                $parents = array_reverse($parents,true);

                // Loop through each parent and add it to the html
                foreach($parents as $parent) {

                if($parent[’published’] && !$parent[’deleted’] && !$parent[’hidemenu’]) {

                if($parent[’id’] == $doc_id) {
                $parent_classes = "$parent_class $current_class";
                } else {
                $parent_classes = "$parent_class";
                }

                $parents_html .= "<li class=\"$parent_classes\"><a href=\"[~$parent[id]~]\">$parent[pagetitle]</a></li>\n";

                }

                }

                // Get the children of the last parent
                $children = $modx->getActiveChildren($parent[’id’]);

                // Loop through each child and add it to the html
                foreach($children as $child) {

                if($child[’id’] == $doc_id) {
                $child_classes = "$child_class $current_class";
                } else {
                $child_classes = "$child_class";
                }

                $children_html .= "<li class=\"$child_classes\"><a href=\"[~$child[id]~]\">$child[pagetitle]</a></li>\n";

                }

                // Complile the HTML into one HTML string
                $html = <<<EOD

                <ul>
                $parents_html
                <li class="$children_class">
                <ul>
                $children_html
                </ul>
                </li>
                </ul>

                EOD;

                // Return the HTML
                return $html;

                Sorry if it’s a dumb question but I’m new to all this....
                  • 32241
                  • 1,495 Posts
                  I don’t see the code is inserting something to the <ul> or <li>, other than the content of pagetitle. Do you have a link where we can look into?
                    Wendy Novianto
                    [font=Verdana]PT DJAMOER Technology Media
                    [font=Verdana]Xituz Media
                    • 22676
                    • 12 Posts
                    Sure, you can see it here:

                    http://www.strangeborders.com

                    Just using the default template now but, like I said, I did try it in another with the same results.

                    Thanks!
                    • I really don’t approve of that sidebar, the way it’s all done in one big <ul>. Each section should be in its own <div class="sideblock"> container, and the <ul> tag should be used for real lists, like menus. That would avoid the problem you’re having. I would have to see your template and chunks to be sure where that extra <li> tag is coming from, from the source it looks like you are using the wrong startDoc id for the menu snippet call, but it’s hard to be sure.
                        Studying MODX in the desert - http://sottwell.com
                        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                        Join the Slack Community - http://modx.org