Jump to content

Pages lookup, excluding already visited


Recommended Posts

Hi all,

I'm building a "news" type site and creating a "related articles" list on article pages.  That's easy enough with tags/categories fields I've setup but I'd like to exclude any articles from the list that have already been viewed by the user that session.

I can of course store the page IDs that have been viewed in a session array.

Is there a way to do this with the PW API eg $pages->find("template=articles, category=localnews, pageid!=34,56,87") or similar?

I know I can pull all pages then exclude in PHP afterwards but would rather do without the extra overhead if possible.



Link to comment
Share on other sites

Shortest topic in history.  I keep assuming things will be more complicated than they are in PW,

The below works if anyone else is looking for the answer.

$pages->find("template=articles, category=localnews, id!=34|56|87") 

  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Similar Content

    • By Vigilante
      This is a pretty typical thing. Open a page, it does a $pages query, finds 112 things and I list them on the page. There is pagination too, 20 per page.
      I want a sort dropdown box so the visitor can change alpha sort or whatever other sorts and filters I eventually use.
      My first thought is to just refresh the page with a url query like "page/?sort=az" and then adjust the query in the template code. But to do this, it will require a page refresh, which means the sort box goes back to its default, and not sure how it effects pagination.
      If I do a page refresh, I'll have to keep the sort settings in the session or something, to make sure I always apply correct sort on page load.
      But at the same time, I've already got the $pages array, it would be much nicer to shuffle it and update the page without a page refresh, rather than run the query over and over again.
      But then again, the pagination buttons already cause page refreshes, so that is already happening anyway, unless I convert the pagination buttons to also be no-refresh somehow.
      I figure this is a very common problem, to paginate results and give users a sorting/filtering option. What is the common methods for handling it? Session, url query, ajax? If I just add the sort to the url query, how do I make that work in the pagination links?
    • By FrancisChung
      Hi there,
      I'm trying to implement a hidden stats page to store various counters and I'm using this article as a basis for my PHP Code
      I've created a stats  page  based on a stats template, and the page is set to unpublished with no other attributes.
      What have I overlooked if the following code returns a Nullpage ?
      $stats = wire(pages)->get("/stats"); I can "get" a homepage without any issue for reference.
    • By iNoize
      i need to sort $pages by the first letter an show on the page like 
         - Aname Page 
         - Aname Page 
         - Aname Page 
         - Aname Page 
         - Bname Page 
         - Bname Page 
         - Bname Page 
         - Bname Page
      How can i check which is the first letter from the page.title ?? 
    • By Matte85
      I have encountered the following problem in the otherwise magnificent CMS ProcessWire:
      I'm sorting pages according to: "$page->children("sort=...". This is principally working fine, but the problem occurs when values like the following are returned: "10,4m3; 10m3; 8m3...". ProcessWire interprets them as text, which means that it thinks that e.g. "8m3" is greater than "10m3" seeing how the earlier begins on a greater number.
      Does anyone have any ideas how I could work around this issue, and indeed get PW to sort the values in the following order: "8m3; 10m3; 10,5m3...".
    • By Mont
      I am looking to display Scorecards on a rider_profile.php page.  I am using a event_results.php page that has a pagetable field that generated the scorecards.  The settings of the pagetable field has the pages being created under a page called scorecards. 
      There are going to be multiple cards throughout the year for each rider depending on how many events they attend.  Since there are multiple cards per rider I set the pagetable setting for Automatic Page Name Format to Ymd:His to create different folders for each scorecard. 
      When I did that my code below doesn't work of course.  How do I search the children folders?  I am using $pages so I don't think I can use children() .
      $event_hx = $pages->get("/2014-season/scorecards/")->find("template=scorecard, Competitor~=$rider"); foreach($event_hx as $hx) echo "<li><a href='{$hx->url}'>{$hx->Event_Name}</a></li>"; Link to Dr Frankenstein's monster.
      I noticed this thread suggested by the forum as related and changed the code to below and it works.
      $pages->get("/2014-season/scorecards/, include=all")
  • Create New...