Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2016-08-03 12:24:17

alesh
Member
From: Miami, FL
Registered: 2005-04-13
Posts: 228
Website

Articles with posted/expired dates overlapping with current article

Is it possible to output a list of articles (from section foo) that have posted/expired dates that overlap with the article currently being viewed?

Perhaps this is related: I have code that determines if there are articles in a section who’s date overlaps with the current date and assigns them to a variable.

<txp:variable name="current-exhibitions" value='<txp:article_custom form="article-id"
time="past" expired="0" break="," section="visual-arts" ><txp:article_id />
</txp:article_custom>' />

And then I can output different things based on whether there are or aren’t any such articles:

  <txp:if_variable name="current-exhibitions" value="">
      <h4><a href="/visual-arts-future">Exhibitions</a></h4>
  <txp:else />
      <h4><a href="/visual-arts">Exhibitions</a></h4>
  </txp:if_variable>

Yes, I have tried turning it off and on.

Offline

#2 2016-08-03 13:37:05

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,011
Website GitHub Mastodon Twitter

Re: Articles with posted/expired dates overlapping with current article

Hi Alesh,

Did you try

<txp:variable name="all-exhibitions"><txp:article_custom 
time="past" expired="1" break="," section="visual-arts" ><txp:article_id />
</txp:article_custom></txp:variable>

Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#3 2016-08-03 13:39:58

alesh
Member
From: Miami, FL
Registered: 2005-04-13
Posts: 228
Website

Re: Articles with posted/expired dates overlapping with current article

colak wrote #300481:

Hi Alesh,

Did you try

<txp:variable name="all-exhibitions"><txp:article_custom...

You’re right—that’s a mistake in my code!

But that code just outputs articles who’s dates overlap with the current date. I’m trying to see if there’s a way to output articles that overlap with the dates of the article currently being displayed?


Yes, I have tried turning it off and on.

Offline

#4 2016-08-03 13:54:29

etc
Developer
Registered: 2010-11-11
Posts: 5,053
Website GitHub

Re: Articles with posted/expired dates overlapping with current article

You will need a plugin for this, I’m afraid:

<txp:etc_query name="all-exhibitions" break="," populate="article"
    data="SELECT ID FROM textpattern WHERE Status=4 AND Section='{?section}' AND UNIX_TIMESTAMP(Posted) <= {?expires} AND UNIX_TIMESTAMP(Expires) >= {?posted}">
    <txp:article_id />
</txp:etc_query>

This will store all overlapping articles ids from the current section in <txp:variable name="all-exhibitions" />.

Edit: logic

Last edited by etc (2016-08-03 20:12:04)

Offline

#5 2016-08-04 13:29:08

alesh
Member
From: Miami, FL
Registered: 2005-04-13
Posts: 228
Website

Re: Articles with posted/expired dates overlapping with current article

Thanks! However, not quite working for me. When I run this it outputs the correct number of articles, but the ID of the current article each time. I just got 1342 , 1342 , 1342 , 1342 , 1342 when viewing article 1342, for which there are in fact four concurrent articles.

I had an old version of etc_query installed. Updating to the newest version fixes it!

Thanks!!

Last edited by alesh (2016-08-04 13:54:29)


Yes, I have tried turning it off and on.

Offline

#6 2016-08-04 14:12:27

alesh
Member
From: Miami, FL
Registered: 2005-04-13
Posts: 228
Website

Re: Articles with posted/expired dates overlapping with current article

Is there some simple way to exclude the current article on the page from the list?


Yes, I have tried turning it off and on.

Offline

#7 2016-08-04 14:22:41

etc
Developer
Registered: 2010-11-11
Posts: 5,053
Website GitHub

Re: Articles with posted/expired dates overlapping with current article

alesh wrote #300503:

Is there some simple way to exclude the current article on the page from the list?

Ah yes, sorry:

<txp:etc_query name="all-exhibitions" break="," populate="article" globals="thisarticle"
    data="SELECT ID FROM textpattern WHERE ID!={?thisid} AND Status=4 AND Section='{?section}' AND UNIX_TIMESTAMP(Posted) <= {?expires} AND UNIX_TIMESTAMP(Expires) >= {?posted}">
    <txp:article_id />
</txp:etc_query>

Offline

#8 2016-08-05 11:15:52

alesh
Member
From: Miami, FL
Registered: 2005-04-13
Posts: 228
Website

Re: Articles with posted/expired dates overlapping with current article

Thanks again very much!

It occurs to me from studying this that SQL syntax isn’t the only thing I’d need to have come up with this myself. There’s some knowledge of the inner workings of Textpattern too (e.g., ?thisid). Is there someplace where that stuff is spelled out? I have the Textpattern Solutions book and it sure doesn’t seem to be there.

(Or is it really just, “it’s all right there in the source code, man!”)


Yes, I have tried turning it off and on.

Offline

#9 2016-08-05 15:17:25

etc
Developer
Registered: 2010-11-11
Posts: 5,053
Website GitHub

Re: Articles with posted/expired dates overlapping with current article

alesh wrote #300505:

There’s some knowledge of the inner workings of Textpattern too (e.g., ?thisid). Is there someplace where that stuff is spelled out? I have the Textpattern Solutions book and it sure doesn’t seem to be there.

(Or is it really just, “it’s all right there in the source code, man!”)

Yes, these are (undocumented) txp internals that you normally don’t need to know about, unless you are writing a plugin. But they are quite easy to understand, just output

<txp:php>global $thisarticle; print_r($thisarticle);</txp:php>

in some article form. The {?thisid} notation comes from etc_query and means $thisarticle['thisid'] in this context. Actually, you should be able to get rid of them (untested):

<txp:etc_query name="all-exhibitions" break="," populate="article" globals="thisarticle"
    data='SELECT ID FROM textpattern WHERE ID!=<txp:article_id /> AND Status=4 AND Section=''<txp:section />'' AND UNIX_TIMESTAMP(Posted) <= UNIX_TIMESTAMP(''<txp:expires format="%Y-%m-%d %H:%M:%S" />'') AND UNIX_TIMESTAMP(Expires) >= UNIX_TIMESTAMP(''<txp:posted format="%Y-%m-%d %H:%M:%S" />'')'
>
    <txp:article_id />
</txp:etc_query>

Offline

Board footer

Powered by FluxBB