How to display news (events) on modx revo depending on the date in one or another block? enter image description here

The content manager indicates the date, and on the basis of this event appears in a particular block.

    1 answer 1

    The question does not indicate how the date is set. If it is specified in publishedon , then you can select news for each of the blocks using the getResourses snippet, comparing the date of the news with the current date.

    For example, for the first block (New), a call to the snippet may be such (for example, news is descendants of a resource with ID == 10):

     [[getResources? &parents=`10` &tpl=`news-block-item` &includeContent=`1` &where=`{"publishedon:>":[[!now]]}` &limit=`4` ]] 

    Please note that publishedon is stored as UNIX-time and the comparison should also be made with the same timestamp value. Snippet now can be something like

     <?php return date("U"); 

    If the news date is set in TV (in the example below - newsdate), then the condition will be different. For example:

     [[getResources? &parents=`10` &tpl=`news-block-item` &includeContent=`1` &tvFilters=`newsdate>>[[!now]]}` &limit=`4` ]] 
    • [[getResources? &parents= [[getResources? &parents= 8` & tpl = ImmediateEvent & includeContent = 1 & includeTVs = 1 & processTVs = 1 & where = {"publishedon:>":[[!toDate]]} & limit = 4444 ]] `I’m putting all the news out - Vyacheslav Yashnikov
    • This prints out [[+ publishedon]]: 2016-09-01 22:52:11, and this prints toDate: 2016-09-02 14:40:27, the format converges, I don’t understand why, it can compare the length of strings to not numbers? - Vyacheslav Yashnikov
    • one
      @ VyacheslavYashnikov Miscarriage out. publishedon is stored in the database and compared as a timestamp , and displayed in formatted form. Therefore, this parameter should be compared in numerical form. I fixed the snippet now in the answer. - tutankhamun
    • @ VyacheslavYashnikov In addition, you need to understand that when storing the publication date the time zone is not taken into account, it must be taken into account when comparing - tutankhamun
    • when there are no resources that satisfy the filter, it displays all the news in general, can this be solved somehow? - Vyacheslav Yashnikov