We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19328
    • 433 Posts
    I'm using getPage / getResources to show only the blog posts of a specific user. I use the &where property to only show posts with a certain ID for 'createdby'. This correctly returns only the posts from the specified user. So all this is working, except for the paging. The paging gives me 4 pages, even if there is only one post. It is like the [[!+page.nav]] placeholder doesn't know the where filter that has been applied. The second, third and fourth page are empty though.

    Because my code has become kind of complicated I've included it all. Maybe the nesting/caching could be the problem.
    I could only get this to work by calling everything uncached (the If snippet, getPage snippet, userID placeholder and page.nav placeholder.

    [[!getUserID? &name=`auteur`]] <!-- sets placeholder 'userID' if author is provided. This works -->
    
    [[!If? &subject=`[[+userID]]` &operator=`notempty` &then=`
    
        <ul class="nonVisualList newsItems">
    
        <!-- the correct posts are shown, only from specified user -->
        [[!getPage? &element=`getResources` &parents=`[[*id]]` &where=`{"createdby:=":[[!+userID]]}` &tpl=`nieuwsRowTplTemp`  
    &showHidden=`1`]]
        </ul>
    
        <!-- page nav is wrong! based on total nr of resources instead of filtered nr -->
        <div class="paging"><ul class="pageList">[[!+page.nav]]</ul></div>
    ` &else=`
    
        <!-- this works and is not the problem -->
        <ul class="nonVisualList newsItems">
        [[!+articles]]
        </ul>
        [[!+paging]]
    
    `]]


    Why would the paging not respect the where filter? Thanks for any help!
      • 4172
      • 5,888 Posts
      is it possible, it does use the total from articles?

      try to change the &totalVar - property
      you may also need to change the &pageVarKey - property
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 19328
        • 433 Posts
        Thanks Bruno, I'm gonna try that. Never thought of the possibility of it interfering with articles. Could be it!

        But first have to fix another problem that has arisen: the above code, which absolutely worked when I posted this, doesn't work anymore after I cleared the cache. The getPage seems to give an error now, the page remains blank. It must have something to do with the nesting... When I get this working again I'm going to try your suggestion. And if you've got any ideas about the nesting/caching problem with the above code I'm all ears of course ;-)

        Edit: I'm on Revo 2.2.8 with this one
          • 19328
          • 433 Posts
          Alright I think I fixed the first problem by doing this:

          [[!getUserID? &name=`auteur`]]
          [[[[!If? &subject=`[[!getUserID? &name=`auteur`]]` &operator=`notempty` &then=`$blogFilteredChunk` &else=`$blogNormalChunk`]]]]

          maybe the parsing order is better now because it seems to work so far. I'm moving on to your suggestion now, Bruno. I'll post back if it works.


          Spoke too soon. Still not working after clearing the cache a few times (first time it worked after I cleared the cache).
            • 3749
            • 24,544 Posts
            If your getUserID snippet returned the ID rather than setting the placeholder, you could just use that snippet tag (uncached) in the getPage/getResources tag instead of the placeholder tag and leave out the earlier getUserID call. I'm not sure it would work any better, but it might and it should be a little faster.
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting
              • 19328
              • 433 Posts
              Thanks BobRay and Bruno, I got it fixed.
              I changed the getUserID snippet to not set a placeholder but return the ID. I also changed a few other things, including adding the totalVar property, and now it works.

              Working code:

              On blog template:
              [[[[!If? &subject=`[[!getUserID? &name=`auteur`]]` &operator=`notempty` &then=`$blogFilteredChunk` &else=`$blogNormalChunk`]]]]


              chunk 'blogFilteredChunk':

              [[!getPage? 
              &element=`getResources` 
              &parents=`[[*id]]` 
              &where=`{"createdby:=":[[!getUserID? &name=`auteur`]]}` 
              &tpl=`nieuwsRowTpl`  
              &showHidden=`1`
              &totalVar=`totalBlogs`
              ]]
              
              <div class="paging"><ul class="pageList">[[!+page.nav]]</ul></div>


              chunk 'blogNormalChunk':

               <ul class="nonVisualList newsItems">
                  [[!+articles]]
                  </ul>
                  [[!+paging]]


              Thanks again for your help!!!