Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
Articles posted today
I feel pretty stupid, because this feels so simple but I have no idea how to make it happen…
How do I get a list of article(s) that have a posted date of today? article_custom
can clearly handle articles posted in the past, future or both, but what about articles posted only today?
I am using the posted date as the date of an event, and I want to particularly highlight today’s events (if any) on the homepage.
I know that I can use smd_query
to do this, but I was sort of hoping that there is some native way of doing this.
Thanks.
[EDIT] And I also want to extract from specific sections only.
Last edited by aslsw66 (2010-02-09 22:05:00)
Offline
#2 2010-02-09 22:20:53
- rsilletti
- Moderator
- From: Spokane WA
- Registered: 2004-04-28
- Posts: 707
Re: Articles posted today
ras_if_dates_v4.2.0.tx will allow you select articles by posted dates, including current date, within the article form. It works well to make display changes, but for filtering articles for display you have to keep an eye on pagination issues and such because it doesn’t alter what is returned by the article tag, only how or if it is displayed.
Offline
Re: Articles posted today
Can this output a list of articles, or does it only work on one article at a time?
[EDIT] Just re-read the help text and it seems this operates at the article level.
What I really need is the ability to pull a list of all articles within specific sections that have a posted date of today, and be able to just display the article title with a link to the full article.
Last edited by aslsw66 (2010-02-09 22:53:02)
Offline
Re: Articles posted today
aslsw66 wrote:
I know that I can use smd_query to do this, but I was sort of hoping that there is some native way of doing this.
Yes there is. Article_custom has month
attribute which can be use to filter posts by date. The timestamp, today, can be selected with a line of PHP. Like so:
<txp:article_custom month='<txp:php> echo safe_strftime("%Y-%m-%d"); </txp:php>'>
<!--
I came today:
-->
<txp:title />
</txp:article_custom>
Offline
Re: Articles posted today
It works!
When I read about this in the textbook, I always assumed that “month” related to some sort of, well, month-based functionality. But now I re-read it, I can see that it can handle year, year and month, or year and month and day.
Thanks for that, I knew there must be some core functionality to do this.
Offline
Re: Articles posted today
So, this part works but now I need to figure out how to exclude these items from a list of future events.
In other words, if there are any events on today these will appear in their own box on the homepage – this works.
Immediately below is another box which shows the next 5 events, but I want to exclude any events on today. Using article_custom time="future"
doesn’t work because any events on later today still appear. I can’t use offset
because I don’t know how many events there are today (if any).
Thanks.
Offline
Re: Articles posted today
Here’s a rather rough idea:
- Start with
article_custom time="future"
. Make thelimit
big enough to include all of any one day’s events, plus 5. - Set a counter variable using adi_calc
- Set a variable matching today’s date
- Inside your
article_custom
form/tag, do anif_variable
check on the date variable you set. If true, show nothing - If false, and if the counter hasn’t exceeded 5, show the article and increment the counter
The date check would look something like:
<txp:if_variable name="today" value='<txp:posted format="%Y%m%d" />'>
with the format
string matching whatever you used when setting the variable.
Code is topiary
Offline
Pages: 1