Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2013-03-21 09:39:27

Algaris
Member
From: England
Registered: 2006-01-27
Posts: 572

[Solved] Display a hyperlinked date to a series of articles

I’m trying to display a series of dates that when clicked returns all of the articles posted on that date.

For instance if I have 10 articles posted on Thursday 21st March and 15 articles posted on Friday 22nd March I would like these dates to be displayed once (with the latest on top). Ideally I’d like to place a limit on the number of dates returned such as the last 14 dates. When a specific date is clicked it should then open a new browser tab displaying all of the articles for that date ordered by a custom field I’ve setup.

Any advice or pointers would be very helpful.

Last edited by Algaris (2013-03-21 15:44:23)

Offline

#2 2013-03-21 11:35:22

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

Re: [Solved] Display a hyperlinked date to a series of articles

You can do it pluginless way, but a direct MySQL query would be much faster:

<txp:etc_query data="SELECT DISTINCT DATE_FORMAT(Posted, '%Y-%m-%d') month FROM textpattern WHERE Status=4 ORDER BY month DESC LIMIT 14">
  <a href="?month={month?}">{month?}</a>
</txp:etc_query>

You might need to modify the WHERE clause to restrict articles to some section/category/etc.

Offline

#3 2013-03-21 12:14:09

Algaris
Member
From: England
Registered: 2006-01-27
Posts: 572

Re: [Solved] Display a hyperlinked date to a series of articles

Thank you Oleg. That’s got the dates out. I’m struggling to figure out how to output articles from the messages section for the selected date though. I’ve tried modifying the WHERE clause as you suggested but keep getting SQL syntax errors.

Offline

#4 2013-03-21 12:19:27

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

Re: [Solved] Display a hyperlinked date to a series of articles

Ross, try WHERE Status=4 AND Section='messages' (with quotes).

Edit: strictly speaking, you should add also AND (NOW() <= Expires OR Expires = '0000-00-00') to WHERE, but if you have no future/expired articles, this is not necessary.

Reedit: and modify the links to point to the messages section:

<a href='<txp:section url="1" name="messages" />&amp;month={month?}'>{month?}</a>

Last edited by etc (2013-03-21 12:34:04)

Offline

#5 2013-03-21 12:27:00

Algaris
Member
From: England
Registered: 2006-01-27
Posts: 572

Re: [Solved] Display a hyperlinked date to a series of articles

Ah I was missing the quotes. That’s squashed the error. I just need to workout why no articles are being displayed when I click the links.

Offline

#6 2013-03-21 12:34:44

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

Re: [Solved] Display a hyperlinked date to a series of articles

Please see my second edit above.

Edit: or

<a href='<txp:section url="1" name="messages" />?month={month?}'>{month?}</a>

if you use some “clean” url mode.

Last edited by etc (2013-03-21 12:41:30)

Offline

#7 2013-03-21 12:44:46

Algaris
Member
From: England
Registered: 2006-01-27
Posts: 572

Re: [Solved] Display a hyperlinked date to a series of articles

Thank you Oleg it’s working fine now. I did have to change your link to include a ? before the &amp; to get it working. Now I just need to play with this to better integrate it with my site.

One quick question. If I wanted to change the links text to Fri 21 2013 instead of 2013-03-21, what would be the best way to do this?

Offline

#8 2013-03-21 12:57:43

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

Re: [Solved] Display a hyperlinked date to a series of articles

Probably

<a href='<txp:section url="1" name="messages" />?month={month?}'>{$date(D d Y|{month?})}</a>

See here for other formatting options.

Offline

#9 2013-03-21 14:34:35

Algaris
Member
From: England
Registered: 2006-01-27
Posts: 572

Re: [Solved] Display a hyperlinked date to a series of articles

Thank you that did just the trick. Now to extract the date variable from the URL so that I can use it in conjunction with <txp:article_custom limit="99999999" month='xxxxxx' time="any" sort='custom_1' />

I’m investigating adi_gps to see this’ll do the job.

Offline

#10 2013-03-21 14:37:35

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

Re: [Solved] Display a hyperlinked date to a series of articles

<txp:etc_query name="month" data="{?month}" globals="_GET" /> will store it in <txp:variable name="month" />.

Offline

#11 2013-03-21 15:43:59

Algaris
Member
From: England
Registered: 2006-01-27
Posts: 572

Re: [Solved] Display a hyperlinked date to a series of articles

Hot digity! Thank you so much Oleg, everything is working just as I wanted it.

Offline

#12 2013-03-21 16:50:39

michaelkpate
Moderator
From: Avon Park, FL
Registered: 2004-02-24
Posts: 1,379
Website GitHub Mastodon

Re: [Solved] Display a hyperlinked date to a series of articles

I did some work on creating Date-Based Archives a while back that might be useful. Unfortunately, the examples got broken in the Joyent-Textdrive changeover.

Offline

Board footer

Powered by FluxBB