We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37261 ☆ A M B ☆
    • 113 Posts
    pyrographics Reply #1, 15 years ago
    We are running a news web site in MODx Revo and Google News inclusion requests a unique five digit numerical code in each article. I can't expect the site editors to insert the code into the alias every time, I can barely get them to add tags, so I would like to do it automatically. I also do not want it to be hard coded so it would be wiped out by future updates. Does friendly URL's or maybe form customization provide a mechanism for this? I searched the settings and didn't see any method of changing the alias auto-population method.

    Thank you, any ideas are much appreciated!
      • 17930
      • 81 Posts
      Just a Thought:
      This may need to be done in a Plugin. I'm just thinking through it.

      If you have a container called news with id of 123 that holds all your news articles it would be a little easier to differentiate news articles from other pages.

      If I were trying this I would then create a Plugin that fired on something like OnDocFormSave but maybe OnBeforeDocFormSave . If you put all your news articles in a container called News, you would be able to query the Resource being saved to make sure it's in the news container by looking at the Parent IDs. That way you make sure to only modify news articles. If they aren't in a container news maybe you could make sure every news article has a specific TV.

      Then you could modify the alias when the Resource is saved. to make sure it contains a five digit number. You would have to query the current alias to make sure you don't keep adding it on so the alias doesn't get longer and longer.

      For the five digit number, I would use the Resource's ID, but modify it a little (but that's because I'm mental about hackers). I would do something like take the ID and multiply it by some random number or reverse it, and then add some leading zeros to make sure it's five digits. Does the number have to be exactly five digits? Because if so, you only have 99,999 news articles you can write.

      When you program the plugin, make sure you take into account that sometimes it will be a new document being saved and sometimes it will be an existing document.
      (It will be something like- modSystemEvent::MODE_NEW or modSystemEvent::MODE_UPD )
        • 32316
        • 387 Posts
        whistlemaker Reply #3, 15 years ago
        one code appended to all URLs ?

        sort of like mynews.com/sports/his-story-12345.html

        where all pages of the site would end with 12345.html

        If so in the manager go to System/Content Types and edit the HTML file extension (in my example it would be 12345.html changed from .html)
          • 37261 ☆ A M B ☆
          • 113 Posts
          Thanks for the feedback, I think the digits have to be unique. From Google:

          Display a three-digit number. The URL for each article must contain a unique number consisting of at least three digits. For example, we can't crawl an article with this URL: http://www.google.com/news/article23.html. We can, however, crawl an article with this URL: http://www.google.com/news/article234.html. Keep in mind that if the only number in the article consists of an isolated four-digit number that starts with 199 or 200, we won't be able to crawl it.

          I'll try the plugin route if our sitemap keeps having problems.
            • 37261 ☆ A M B ☆
            • 113 Posts
            This was actually fairly easy to accomplish by using the plugin method and a unix timestamp as the unique number. For anyone else who's attempting:


            $evt=$modx->event;
            if($evt->name=='OnBeforeDocFormSave')
            {
                if($evt->params['mode']=='new'){
            $pagetitle = $resource->get('pagetitle');
            $append = time();
            $notwant=$modx->config['friendly_alias_restrict_chars_pattern'];
            $alias=strtolower(preg_replace($notwant, '-', $pagetitle)).$append;
            $resource->set('alias',  $alias );
            	}
            }