News Expiry after 2 months

Hey everyone, looking for some technical guidance here. I am needing to expire some News posts (News is a custom module) after 2 months. I don’t want to use the Release/Expiry Date to run this, as I need these posts to still live on the main News Page (so I can’t have them expire).

I know how to expire things well for simple modules using SearchScope, but trying to figure out how to make this work if it is past 2 months that the article has been active.

Here is the scenario:

  • Client has 3 news posts that are featured on the home page. Sorted by release date (descending).
  • When a post date is past 2 months (let’s say 60 days) from the release date, it disappears
  • If all 3 news posts are expired, then the whole section disappears.

I’m sure I can figure all of this out on my own, and will more than likely run all of this using a FORLOOP so I have a bit more control on page (especially for the actual section they are sitting in.

I guess my question is, I will be using “now” in my search scope, i.e. prop_ReleaseDate_Min to set the minimum date, but I am trying to introduce a variable where it also checks 60 days out and doesn’t show it if it exceed the 60 days.

Is all of this making sense? Lol?

Thanks,
Aaron

Could something like this work:

{% component ... searchScope: "{'prop_ReleaseDate_Min':'{{ "now" | date_add: -60, "day" | date: "%Y-%m-%d" }}'}" ... %}
2 Likes

Or adjust plus or minus days, or ReleaseDate_Min/Max depending on how you need the date range to be.

1 Like

This might work! Thanks @Adam.Wilson - going to try it out tomorrow. Will report back if successful.

So, totally worked Adam! Thanks so much. Here’s another one. Any way to ‘offset’ the first item using searchScope, or within the module tag? I know I can offset the first item using a FORLOOP, but I want to be able to have it offset from the module tag rather a loop.

Reason, I have the most recent article separate from this, further up the page, so I don’t want it to duplicate in the bottom news articles.

So just ended up using a mix of searchScope and a collection in order to achieve the offset option. All is good and it worked.

{% assign dateMinus = “now” | date_add: -60, “day” | date: “%Y-%m-%d” %}
{% component source: “TCYBA Blog”, sortBy: “releasedate”, searchScope: “{‘prop_ReleaseDate_Min’:’{{dateMinus}}’,‘prop_FeaturedArticle’:false}”, sortOrder: “DESC”, limit: “5”, object: “collection”, collectionVariable: “homeFooterNews”, type: “module” %}
{%- for item in homeFooterNews.items offset:1 limit:3 %}
{% component type: “snippet”, alias: “footer_home_blog_items” %}
{% endfor -%}`

Thanks again for your help @Adam.Wilson

1 Like

Ok, so to further this, I almost need this now in reverse.

{% assign dateMinus = "now" | date_add: -60, "day" | date: "%Y-%m-%d" %}
{% component source: "TCYBA Blog", layout: "List", sortBy: "releasedate", searchScope: "{'prop_ReleaseDate_Min':'{{dateMinus}}'}", sortOrder: "DESC", limit: "12",type: "module" %}

This is working well on the home page. But I need to output all Blog Items on the Blog Main Page, except for the articles that are not within 60 days, while still including a limit and pagination. Any suggestions @Adam.Wilson ?

Thanks,
Aaron

Change to prop_ReleaseDate_Max

Then the maxium date would be today -60 days.

2 Likes

Yup, that did the trick. Thanks @Rhatch