We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36447
    • 98 Posts
    I want to retrieve articles from a page outside of articles based on the assigned tags.

    This is a common task where various posts are stored in Articles but may be needed in other pages throughout the site, such as a page outside of the Articles container that offers news items assigned a specific tag (or multiple tags).

    The manual describes how to retrieve articles using getResources (http://rtfm.modx.com/display/ADDON/Articles.Retrieving+Articles+Outside+of+Articles), but doesn't explain how to use tags in retrieving articles. Is this possible? [ed. note: puffin2 last edited this post 11 years, 8 months ago.]
      • 36447
      • 98 Posts
      OK, I futzed around til I came up with a solution. If you've assigned tags to posts, then you're using the default TV: articlestags. So it's just a matter of making the correct call using &tvFilters. For example, my articles reside under resource "4" and I want to retrieve all posts tagged with "PA":

      [[!getResources?
        &parents=`4`
        &tpl=`your.ArticleRowTpl`
        &showHidden=`1`
        &limit=`20`
        &includeTVs=`1`
        &processTVs=`1`
        &tvFilters=`articlestags==PA`
      ]]
      [ed. note: puffin2 last edited this post 11 years, 8 months ago.]
        • 36447
        • 98 Posts
        Ahh, not so simple after all.... The above call works for posts assigned single tags but not for posts assigned multiple tags.

        For example, take a post assigned these tags (EPA,PA,TX,NJ). If you use the call above, this post will not be retrieved. You can expand the call using %PA% which returns all posts that contain "PA" but you'll also be returning all posts containing the tag "EPA." The only solution is to include one and exclude the other:
        &tvFilters=`articlestags==%PA%,articlestags!=%EPA%`

        Such a solution becomes quite complex when dealing with many tag combinations. What we need is better filtering ability when using &tvFilters to retrieve posts from multiple-tagged articles.

        If someone has a better solution, I'd love to hear it. [ed. note: puffin2 last edited this post 11 years, 8 months ago.]
          • 20135
          • 188 Posts
          Thanks for you solution. I'm using it with jquery UI tabs, and it seems to be working. However, what I'm noticing is that, rather than retrieving only the articles by the particular tag, it's doing this. For every article with that tag, it's displaying ALL of the articles. So if there are 6 articles, 2 of which are tagged, it will show 6 articles 2 times. Did you have this problem? If so, what did you do to correct it?

          [[Edit]] All good - I was using "@INLINE [[+latest_posts]]" for the tpl, and realised that was the problem. Changed it to the (duplicated) default template for latest posts, works great. [ed. note: moniarde last edited this post 11 years, 2 months ago.]
            • 42562
            • 1,145 Posts
            Enter and Retrieve Tags outside of Articles

            For anyone using the wonderful NewsPublisher by Bob Ray: just make sure the articlestags TV is obviously connected (has Template Access) to your Template (even if not connected, Articles has a way of using the values of the Tv)

            If not connected and you try to use NewsPublisher, you'll get the error: you are trying to use a TV that does not belong to blah blah. Once connected, everything becomes merry happiness.
            Use existing tags, create new tags, use multiple tags. And in all, the Articles [[+tags]] will respect your input nicely.

            Then you can use the above getResource call to make yourself even more happy...

            One day, I was just mighty angry for nothing, at the fiction that NewsPublisher and getResources won't work with Tags. So I gave it a shot, and voila! I thank myself for daring and not wallowing in ignorantissimusness.
              TinymceWrapper: Complete back/frontend content solution.
              Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
              5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.