We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 813 ☆ A M B ☆
    • 326 Posts
    I'm guessing this has an easy solution that I'm just not thinking of...

    I've got a Revo site that's essentially a blog, in which all entry resources are stored within a single resource subfolder. In the blog, I'd like to treat each resource like a "chapter" (narratively speaking) in an ongoing story. The chapters' order should be based on ascending publish date for its sort order.

    In other words, for any given blog entry, I want to be able to identify its order in the overall blog, starting at 1, based on ascending published date. Any ideas?
      • 9207 ☆ A M B ☆
      • 2,475 Posts
      Can you just sort your pages based on publication date? Or am I missing something? Typically you'd just specify the sorting parameter in your Snippet call -- often you'd use getResources or Wayfinder for this.

      getResources would use this parameter:
      &sortby=`publishedon`


      Whereas Wayfinder would use this:
      &sortBy=`publishedon`


      Or you could sort on the "menuindex" if you wanted to drag your resources around into your own arbitrary order. You can easily sort on any of the document's native fields (listed here http://rtfm.modx.com/display/revolution20/Resources#Resources-ResourcesResourceFields).

      Is that helpful?
        • 813 ☆ A M B ☆
        • 326 Posts
        That's close, but not exactly what I need. I don't just want to sort by it, which I understand (I'm already doing that on an archive page). I want to be able to pinpoint where a specific article falls in the totality of articles.

        For example, when the tenth resource is posted, and its pagetitle is "Everything about Widgets", I want the top of the individual resource page to read something like, "Chapter 10: Everything about Widgets", and for "Chapter 10" to be based upon pubdate, so it's automated.

        So, sorting is not the issue; figuring out and displaying where the article falls within the sort is what I'm looking for.
          • 813 ☆ A M B ☆
          • 326 Posts
          Also, I'm saying that I want this for the individual resource page, which is true. However, I'd also like to display it in an archive list, so extending what I'm asking for to not just the individual but the all list would also be beneficial. Thanks!
            • 9207 ☆ A M B ☆
            • 2,475 Posts
            Ah. So you just need to count the number of total chapters? The low-brow solution here would be to hard-code it. That takes less effort on the application and you don't have wave a magic PHP wand. How often do you think you'll be adding chapters?
              • 813 ☆ A M B ☆
              • 326 Posts
              Yes, count the number of total chapters, but also figure out where the specific resource falls in that count based on pubdate. Chapters will be added pretty regularly, since a "chapter" is basically just a blog post.

              It sounds easy, but I haven't quite figured out the cleanest syntax to pull it off.
                • 813 ☆ A M B ☆
                • 326 Posts
                BTW, I vaguely remember Wayfinder having a placeholder kind of like this in Evo, although not exactly. I think it was called &rowIdPrefix (about 1/4 down the page):

                http://muddydogpaws.com/development/wayfinder/parameters.html

                That's the closest thing I've seen to what I want, but if I'm on an individual resource page, I'd hate to have to load Wayfinder just for that one value.
                  • 4172
                  • 5,888 Posts
                  If you make sure they are sorted by menuindex in the correct order you can use the menueindex-field as chapter-number.

                  It would also be possible to create a plugin for onDocFormSave which stores the correct chapter-value to a TV by the order based on publishedon.
                    -------------------------------

                    you can buy me a beer, if you like MIGX

                    http://webcmsolutions.de/migx.html

                    Thanks!
                    • 813 ☆ A M B ☆
                    • 326 Posts
                    The problem with menuindex is, the author is allowed to pre-date articles (many were written before the blog went live, but need to have the correct creation date). I could certainly use menuindex, but it creates a discrepancy between menuindex and pubdate that requires a lot of manual correction. What I'm trying to figure out would be the cleanest and most automatic, but is a bit non-MODx-y.

                    Walking through it, I think it looks like this:

                    1. Sort all resources in a subfolder by pubdate ASC, and put in an array.
                    2. Get pubdate of resource in question.
                    3. Cross-reference pubdate with ID of resource.
                    4. Count that resource's place in the array.

                    I think that's it, anyway. I can probably write the code to do this, but it just seems sloppy. I guess what I'm asking is, is there a more MODx-friendly way to do this? Or does someone want to help me write this code? ;-) It seems like it would make for a nice little utility snippet that I'd be glad to give co-authorship for. [ed. note: aladage last edited this post 14 years, 10 months ago.]
                      • 4172
                      • 5,888 Posts
                      I think it's better to create a plugin which does this, when an new article is published:

                      1. search for the latest stored chapter-number (sortby = chapter, sortdir = DESC, limit = 1)
                      2. search for published articles ordered by publishedon, where the chapter-number is empty.
                      3. store the new chapter-numbers into a chapter-tv or another unused resource-field.




                        -------------------------------

                        you can buy me a beer, if you like MIGX

                        http://webcmsolutions.de/migx.html

                        Thanks!