We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 15511
    • 12 Posts
    I’m new to Modx, so please bear with me here.

    We have a news archive of several thousand articles that I am looking to transfer to Modx in order to become more familiar with the system. We are looking to utilize Modx’s friendly URLs/aliases as well as Ditto to create a news archive.

    We are looking to have URLs like follows:

    http://site.com/news/2009/10/31/article-title-goes-here.html

    I know that I could create endless containers for every year, month, and day, but there has got to be a better way to do this. I was thinking of either using the published date in the URL, or having 3 template variables (Or something else) that could be entered when the user is entering the article - year, month, day - that would then show up in the URL.

    So how can we do this? I’m hoping I’m overthinking it and that it’s got a simple solution.

    Looking forward to your advice.

    Kevin
      • 3749
      • 24,544 Posts
      How about putting the date in the alias field with dashes instead of slashes?

      You could write a utility snippet that would do it for you.
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 15511
        • 12 Posts
        There is an idea I hadn’t though of, though this will need to be dead simple for my client to be able to do it (Ideally it would be done automatically)

        I’m a programmer by trade, so I’ll see what I can come up with. Any documentation about creating utility snippets?
          • 3749
          • 24,544 Posts
          I didn’t mean to imply that there was such a thing as a utility snippet. It would be a regular snippet, but would just alter the database rather than producing output for site visitors (although you’d probably want it to print feedback on what it was doing).

          Essentially, it would just walk through the modx_site_content table (using the MODx DB:API) and use the createdon field to generate what you want, put it in the alias field, and update the DB.

          BTW, a plugin could do this for new documents (filling the alias field automatically from now()) -- though that would be trickier -- so the client wouldn’t have to be involved at all.

          I’d suggest some code, but there are people here a lot better than me at date manipulation and DB interaction.
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 15511
            • 12 Posts
            I’m great with the PHP date functions and database stuff. As stated, I do this for a living. I’m simply new to the world of Modx (Recommended to me by this client)

            So, I need a plugin that will run after the content is created or edited. Said plugin will read the published on date and alter the entry with a new alias automatically. So I guess I only have 2 questions:

            1. How do I create a plugin that runs automatically when content is saved (Or a link to a plugin that already does this would work..I could work backwards from it)

            2. What variables would I access to get to the content ID and published date?
              • 3749
              • 24,544 Posts
              I’m not sure, but I think you’d want your plugin to listen for the OnBeforeDocFormSave event and all you’d need are the the ’alias’ field and either the ’createdon’ or ’publishedon’ fields (depending on whether you want the date it was first saved, or the date when it last changed from unpublished to published).

              The fields should be available at that point as $_POST[’fieldname’] and if you change that it should do what you want -- I know it works in MODx Revolution.

              $pubdate = $_post['publishedon'];
              
              // your code here to create the $output string from $pubdate
              
              $_POST['alias'] = $output;

              http://www.sottwell.com/how-plugins-work.html
              http://svn.modxcms.com/docs/display/MODx096/Plugins

              Note that this wouldn’t effect any documents until you edited and saved them. The utility snippet I described above would reset all of them.

              Also, I’m not sure it would work with new documents since the publishedon date might not be set at that point. If so, you could detect that (empty($_POST[’publishedon’]) ) and use time() to generate the contents of the alias field. You’d only want to do that if $_POST[’published’] == ’1’.

                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting
                • 15511
                • 12 Posts
                Thank you for the detailed information. I assume plugins are easily transferred to upgrades...?

                Another question - Should I choose to simply do friendly URLs and NOT modify the alias, will Modx automatically detect if there is an identical title (IE /news/article-title.html) and auto-correct that? Just curious how the system handles that particular situation.

                Thanks again. I’ll look more at the plugin docs later tonight.
                  • 15511
                  • 12 Posts
                  I just looked at the plugin docs and this is going to be a breeze. Just 30 seconds of coding should do exactly what I need to do.

                  Thank you for your direction here.
                    • 3749
                    • 24,544 Posts
                    Now you seew why programmers love MODx. laugh

                    Any plugins you create won’t be touched on upgrade.

                    MODx won’t mess with the aliases and collisions could be a problem with friendly aliases on. You could avoid collisions by adding the pagetitle or some other field (ID probably isn’t available at that point for new docs) into the alias somewhere.
                      Did I help you? Buy me a beer
                      Get my Book: MODX:The Official Guide
                      MODX info for everyone: http://bobsguides.com/modx.html
                      My MODX Extras
                      Bob's Guides is now hosted at A2 MODX Hosting
                      • 15511
                      • 12 Posts
                      Indeed - I’ve already coded what I need it to do and it’s working perfectly (Collisions and all)

                      Now my next question, since I’ve got you here - I need to GREATLY simplify the manager interface for my client. For example, for entering a news article, I only need her to see 2 fields - Title and Text (I assume here somehow renaming the title and content fields would be appropriate) - Everything else can be hidden, as it will simply confuse her. Then, for say, a testimonials section, those fields might be testimonial subject, testimonial submitter, testimonial text. I found ManagerManager, which *appears* to do what I’m looking to do, but I so far am having no luck getting it to work. It’s installed and activated, and I’ve copied the default rules into the rules file, but I see no changes when editing page contents. Any tips or links for this one?

                      Thanks again. I’m liking this more and more.