We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21122
    • 153 Posts
    Hi there,

    I’m in the process of building a site with an integrated blog. I’m using tags for the blog, and all is working well so far. However I need a feature where I can list related news articles (they dont have to be news articles, but related resources). I figured the best way to do this would be to list resources which share the same tags as the current resources.

    So if I’m on the page for a news article which has been tagged ’dogs’, ’cats’ and ’bananas’, I’d like to be able to list the 5 most recent resources which have been tagged with any of those tags. I think the problem is that to get a list of all the news articles with one specific tag, it uses the GET parameter, and obviously when a user navigates to a certain story, they won’t necessarily have that tag in the URL.

    I know there are easier ways to accomplish something similar (like using getResources on resources in the same category for instance) but I’d like to get it figured out with tags if possible!

    Any ideas?

    Thanks
      • 33968
      • 863 Posts
      How about tagLister, using the getResourcesTag part... haven’t tried it but looks like it does what you want.
        • 21122
        • 153 Posts
        I am actually using tagLister and toLinks to display the tags, and then the resources with the clicked on tag.

        I’m just not sure how to go about listing resources on a page which are tagged with similar terms to that of the resource being viewed.

          • 21122
          • 153 Posts
          It seems that this is a common feature request, as shown in this thread http://modxcms.com/forums/index.php?topic=53530.0

          Displaying a list of items which have similar tags, but not via the GET parameter.

          Hmmm...
            • 33968
            • 863 Posts
            Looking at the snippet code, you could probably just add &tag=`tag_name` and it will ignore (or not require) any url parameters.
            [[!getResourcesTag? &parents=`6` &tagKey=`my_tv` &tpl=`mytpl` &tag=`tag_name` ]]
            

            Where ’tag_name’ is the tag you want to list by.

            It won’t work if you want to go by a list of tags - eg: (&tag=`tag1,tag2,tag3`).
            The snippet could be modified to allow for this though.
              • 21122
              • 153 Posts
              Possibly, but this needs to be something thats dynamic, so I could just call all the resources which share the tags of the resource currently being viewed.
                • 20358
                • 10 Posts
                Hmm, I might have to play around with this later. I originally ditched the idea of tags on my blog, because I didn’t really see them being useful. I’m currently just using getResources to get related recent activity based on "category".

                I have a parent resource called "Blog", which is a container and has a getResources call for the main paged. Under that resource, I have multiple container resources titled based on their category (ie. Technology, Videos, etc). These are set to be hidden from the menu and I post my actual blog entries into the appropriate container.

                Then in a sidebar, I have a getResources call that does this:

                [[!getResources? 
                &parents=`[[*parent]]`  
                &tpl=`blogActivity`
                &hideContainers=`1`
                &includeContent=`1`
                &limit=`10`
                ]] 
                



                On the main blog page, this returns latest posts, regardless of category. However, once you click on a post to read it, the sidebar updates and lists only the posts that are also under that same "parent" (category).

                If you are only using tags as a way to represent category, you could probably ditch tags in favor of a similar getResources approach to what I’m using. However, after pondering a bit, I can see tags being useful as a "sub-category" and a way to list a single post with multiple sub-catgories.

                I bet getResourcesTag could accomplish this. See this post: http://modxcms.com/forums/index.php/topic,61744.0/topicseen.html

                It looks like the first reply has a way to display a page with resources that have similar tags. I bet this can be trimmed down to a simple ordered list with linkable titles that you could put in a sidebar or something.

                Swill
                  • 33968
                  • 863 Posts
                  Quote from: neilp123 at May 09, 2011, 10:44 AM

                  Possibly, but this needs to be something thats dynamic, so I could just call all the resources which share the tags of the resource currently being viewed.
                  This could be done like this:
                  [[!getResourcesTag? &parents=`6` &tagKey=`my_tv` &tpl=`mytpl` &tag=`[[*my_tv]]` ]]
                  

                  The current document’s tags are inserted into the &tag=`` parameter.

                  However I don’t think it will work if the current document has more than one tag. But getResourcesTag could be modified fairly easily to split multiple tags into an array and return a list of other documents sharing those tags.
                    • 4172
                    • 5,888 Posts
                    sorry, posted the wrong snippet.
                      -------------------------------

                      you can buy me a beer, if you like MIGX

                      http://webcmsolutions.de/migx.html

                      Thanks!
                      • 21122
                      • 153 Posts
                      Quote from: Mr. at May 09, 2011, 12:34 PM


                      I bet getResourcesTag could accomplish this. See this post: http://modxcms.com/forums/index.php/topic,61744.0/topicseen.html

                      It looks like the first reply has a way to display a page with resources that have similar tags. I bet this can be trimmed down to a simple ordered list with linkable titles that you could put in a sidebar or something.

                      Swill

                      Hi there,

                      Yes, I know I could accomplish something in the way of a related post by using getResources, but as you say, it would only be able to grab recent posts in the same category. Although they would most certainly be related posts, there could easily be posts that are also related that are in different categories.

                      The problem with the example shown in the thread that you’ve linked to is that the page displaying a list of posts which share the same tag is only shown when you click on that tag (because the snippet gets the tag name from the URL). If, for instance, a user navigates to the news section of a website, then clicks on one of the stories, there is no tag in the URL, so no related stories would be shown.

                      I’ve been in touch with Mark Hamstra (one of the MODx Devs) and he’s very kindly helping me out with a solution. Its not the one I’m after (a tag based solution) but it would suit my needs. It relies on the user to select related documents manually. While this may not be perfect, you can’t argue that at least it would be accurate!

                      I think I’ll also have a chat with one of our developers to see if they can build the exact tag-based snippet I’m after!