We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3071
    • 99 Posts
    Has anyone come across any kind of internal link plugin for MODX? There is a marvellous one for Wordpress called SEO Smart Links, but never seen any other. What this does is allows you to specify keywords within your pages and then it addes an href link to them and points at the page of your choice.

    Just so I am clear, I have a wesbite on popstars (for example) so I can specify the following

    Keyword URL


    "Madonna" - http://www.mypostarwebsite.com/madonna
    "Michael Jackson" - http://www.mypostarwebsite.com/michael-jackson

    So I can tell this plugin - "everytime you spot the word "Madonna" automatically place a href link on this word and point it to the page I specify, which in this case is "http://www.mypostarwebsite.com/madonna" "

    Sorry if this sounds patronising but just want to make myself clear! Plus I am a novice anyway! Thanks for any help in advance
      • 20413
      • 2,877 Posts
      (EVO) You could write a plugin "OnParseDocument"

      Example
      $output = &$modx->documentOutput;
      $output = str_replace("maddona", '<a href="maddona.html">maddona</a>', $output);
      return $output;
      
        @hawproductions | http://mrhaw.com/

        Infograph: MODX Advanced Install in 7 steps:
        http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

        Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
        http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower
        • 3071
        • 99 Posts
        Thanks but I am an utter novice! Are you saying create a plugin called ’OnParseDocument’ In the plugins section, then copy that code into it, when I chaged the madonna keyword of course? I am assuming that the parsing bit means it will add the link as the document is served? Also what would I put in the configuration box on this plugin? I fully understand if you don’t have the time to answer these, I am ok with kid’s bullet points though!
          • 3071
          • 99 Posts
          WOW! I’ve done it! I know what you mean now, by the parse thing, Hey thanks a lot, really appreciate that.
            • 3071
            • 99 Posts
            What about if I only want it to link the 1st instance of a particular keyword on any particular page? I also need it to limit the amount of single keywords to link. I.e., I want it to link a maximum of 3 keywords per page, and only 1 instance of each keyword, so if there’s 2 ’Madonna’ keywords, only do the first one.
              • 3071
              • 99 Posts
              Another problem I just came across is, when the href link is the same name as the keyword (very likely indeed!) then the plugin sees this word as well and tries to put a link on the link! So need it to ignore the href as well. Any helpful php wizards out there?
                • 15953
                • 123 Posts
                I tried it, but when testing in my browser (separate PC) the page hangs at a blank white display. I assume the plugin is triggered through the "OnParseDocument" event?
                  • 3071
                  • 99 Posts
                  It works fine for me, BUT if you use the same keyword in the href text it also becomes linked which messes the whole web page up of course! I don’t have enough php knowledge to edit the kind gentleman’s code. Need to add the following:

                  1) A condition that stops the plugin seeing the href as the text specified to link to
                  2) A condition that tells the plugin to only hyperlinke the first example of the text it sees per page
                  3) A condition that allows the creation of more than one keyword to link, although this one’s likely to be simple
                  4) A condition that tells the plug in to stop at 3 links per page (3 different keywords that is)

                  No idea how to do it. >:(
                    • 20413
                    • 2,877 Posts
                    Quote from: benchesters at Aug 31, 2010, 11:35 AM

                    1) A condition that stops the plugin seeing the href as the text specified to link to

                    Add some space to the word we search.
                    $output = str_replace(" maddona ", ' <a href="maddona.html">maddona</a> ', $output);


                    Quote from: benchesters at Aug 31, 2010, 11:35 AM

                    2) A condition that tells the plugin to only hyperlinke the first example of the text it sees per page
                    Use this php function http://www.webmaster-talk.com/php-forum/21334-str_replace-only-once-occurence-only.html

                    Quote from: benchesters at Aug 31, 2010, 11:35 AM

                    3) A condition that allows the creation of more than one keyword to link, although this one’s likely to be simple

                    Just add another line:
                    $output = str_replace(" maddona ", ' <a href="maddona.html">maddona</a> ', $output);
                    $output = str_replace(" mrhaw ", ' <a href="mrhaw.html">mrhaw</a> ', $output);
                    


                    Quote from: benchesters at Aug 31, 2010, 11:35 AM

                    4) A condition that tells the plug in to stop at 3 links per page (3 different keywords that is)

                    Need to google that to...
                      @hawproductions | http://mrhaw.com/

                      Infograph: MODX Advanced Install in 7 steps:
                      http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

                      Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
                      http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower
                      • 15953
                      • 123 Posts
                      I changed keyword but still get blank page. I’m using Revo. I trigger the plugin "OnParseDocument"