We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 1371
    • 9 Posts
    I want to show a list of related posts at the end of each article, based on keywords found in a TV named ’tags’ and seperated by commas.
    What is the best way to do this?
      • 1778
      • 659 Posts
      In Revolution you can use the add-on getResourcesTag, have a look at http://rtfm.modx.com/display/ADDON/tagLister.getResourcesTag

      Cheers
        • 1371
        • 9 Posts
        thanks for the quick reply.
        From what I understand, getresourceTag displays related tags from the ’GET’ parameter in the URL, not from a TV. How do I set it to extract the keywords from a TV called ’tags’? Do you mind giving me the syntax? Thanks!
          • 1778
          • 659 Posts
          look at the related docs :

          http://rtfm.modx.com/display/ADDON/tagLister.tagLister
          and http://rtfm.modx.com/display/ADDON/tagLister.tolinks

          getResourceTag is one of the 3 snippets composing tagLister...

          Cheers
            • 1371
            • 9 Posts
            sorry, I still don’t get how to do this without having the keywords sent in the GET param. I’m familiar with tolinks and taglister and have used them before.
            Tolinks create a list of linkable tags while taglister lists the most commonly used tags on the site. They do not show related post titles. This sounds like a job for getResourceTag, like you said, but I don’t know if it can handle tags coming from a TV instead of from the GET Param and how to do it.
              • 18373 ☆ A M B ☆
              • 3,141 Posts
              If you’re still looking for an answer... here’s a different method I recently used for a related pages sort of thing.

              - Make a TV with input type Multi Select box
              - Input option values something like this:
              @SELECT pagetitle,id FROM `revo_site_content` WHERE parent BETWEEN '8' AND '33'

              where revo_site_content is the full table name for the site_content table, and the WHERE clause is adapted to the parents your related posts can be in (eg your articles parent).
              - Output type delimited list, delimited by a comma in my case.

              What this will do is create a multi select box with the page titles matching your select query, and, when you output the template variable, show a comma delimited list of selected id’s.

              Using this you can then transform them back into a pagetitle with link using a custom output filter (= a snippet).

              This is the snippet I used to grab the pagetitle, and add in a lil’ link:
              <?php
              if ($input == null) {
                  return 'Geen relevante artikelen gevonden.';
                }
                $lpr_ids = explode (',', $input);
                foreach ($lpr_ids as $a => $key) {
                  $document = $modx->getObject('modResource', array(
                    'published' => 1,
                    'id' => $key));
                  $title = $document->get('pagetitle');
                  $output[] = '<a href="'.$modx->makeUrl($key, '',array('i' => 'lex-rel-'.$modx->resource->get(id))).'" title="'.$related.' (Related)">'.$title.'</a>';
                }
                return implode(', ',$output);


              Hope this helps somebody.
                Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

                Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
                • 4971
                • 964 Posts
                So this is a "related posts" by parent,right?
                not by tag or title?

                If the articles under a parent are not related on topic,
                then the results will look kind of iffy, arent they?
                  Website: www.mercologia.com
                  MODX Revo Tutorials:  www.modxperience.com

                  MODX Professional Partner
                  • 18373 ☆ A M B ☆
                  • 3,141 Posts
                  Sorry for being unclear.


                  The template variable shows a multi select box with all the resources under a parent, which allows you to select them yourself. It shows the pagetitle so you can decide which are relevant and which are not.

                  It’s not automatic like taglister, but it’ll give the best results as they are hand picked for all posts. (altho taglister is not really automatic either, as that requires giving in tags)


                  The example @SELECT binding I posted gets all resources under the parents 8-33, but that should be changed to your containers.
                    Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

                    Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
                    • 20349 ☆ A M B ☆
                    • 453 Posts
                    Can somebody explain how to do this in EVO v 1.0.4.

                    undecided
                      BASE - Web Design Studio
                      MODX Ambassador

                      Website
                      • 18373 ☆ A M B ☆
                      • 3,141 Posts
                      Similar to what my earlier post said, but then used on an Evo site:

                      TV with input value:
                      @SELECT pagetitle,id FROM cms_site_content WHERE parent='9' ORDER BY menuindex ASC

                      (where cms_ is your table prefix, and parent=’9’ should be modified to your site)

                      The call in your template:
                      [!Process? &data=`[*tvname*]`!]


                      Process snippet:
                      <?php
                      if ($data == '') {
                          return '<h4>Wij helpen u verder!</h4><p>Voor meer info belt u met ons secretariaat of kijkt u op de contactpagina.</p>';
                        } else {
                          $cp = explode (',',$data);
                          $depText = (count($cp) > 1) ? 'contactpersonen helpen' : 'contactpersoon helpt';
                          $output = '<h4>Contactpersonen</h4><p>Onderstaande '.$depText.' u graag verder!</p><ul>';
                          foreach ($cp as $a => $key) {
                      
                            $doc = $modx->getDocument($key);
                            $output .= '<li><a title="'.$doc['pagetitle'].'" onmouseover="ajax_showTooltip(window.event,\'[~'.$key.'~]\',this);return false" onmouseout="ajax_hideTooltip()" href="[~9~]">'.$doc['pagetitle'].'</a>';
                          }
                          $output .= '</ul>';
                          return $output;
                        }
                      ?>


                      This code seems overly difficult, but that’s due to the overly difficult way of the markup being generated. Just look at what’s being put in the $output part and the variables that are in there and what they seem to grab.
                        Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

                        Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.