Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-12-01 05:54:02

speeke
Member
From: Bruny Island, Australia
Registered: 2009-03-29
Posts: 161
Website

Section article listing beginning with current day's article

I have a section which has 365 articles (one written on each day of the year). On the section page I would like to display an article list comprising 3 article excerpts: the article excerpt that corresponds to the current day (eg 1 December), followed by the two previous article excerpts (eg 30 November, 29 November). Pagination should allow for past articles on previous pages, and future articles on next pages. All of the articles have a status="live".

So, I was wondering how to use the <txp:article /> tag and the corresponding sort attribute, so that the article list doesn’t show the 3 latest article excerpts first (ie 31 December, 30 December, 29 December) – which is the default, but shows the current day, and previous two day’s articles, instead.

NB: These articles were written in 2003, but I want them to show according to the day and month that corresponds with the current year (eg 2009).

Hope all this makes sense, and appreciate any feedback :)

Last edited by speeke (2009-12-01 05:56:29)


“People who value their privileges above their principles soon lose both.”
Dwight D. Eisenhower

Offline

#2 2009-12-01 09:42:50

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,493
Website

Re: Section article listing beginning with current day's article

Assuming the Posted dates correspond with the actual date you want the articles to appear (i.e. though they were written in 2003 they had future posted dates), can you use ras_if_dates in any way, shape or form?

Option 2 is perhaps chh_article_custom which is supposed to be able to limit articles by date, though in anything but Live mode you’ll see a load of warnings on your pages.

Failing that, if you happen to have smd_calendar installed you can probably use <txp:smd_cal_now /> to get the date(s) you want and plug them into an article_custom or three (not very efficient, and I must break that function out into its own plugin one day because it’s rather useful). Alternatively, smd_calendar’s smd_article_event tag might be able to conjure you up a list, since it’s essentially a souped-up article_custom (this also works well if you have the posted dates in a custom field and not in the traditional Posted/Expires location).

On the last rung, you’re into the realms of smd_query I think. How’s your SQL? ;-)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#3 2009-12-01 10:07:58

speeke
Member
From: Bruny Island, Australia
Registered: 2009-03-29
Posts: 161
Website

Re: Section article listing beginning with current day's article

Hi Bloke,

I don’t mind the odd bit of SQL, and have your trusty smd_query to hand ;) But I’m not sure how pagination would work, forward and backward through the list. Can you point me in the right direction?


“People who value their privileges above their principles soon lose both.”
Dwight D. Eisenhower

Offline

#4 2009-12-01 10:24:41

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,493
Website

Re: Section article listing beginning with current day's article

speeke wrote:

I’m not sure how pagination would work, forward and backward through the list

Ah yes, pagination. The bane of smd_query :-(

Unfortunately, the only decent way of doing it (unless someone can correct me) is to grab the ?pg variable and use it to calculate the offset attribute. adi_gps and adi_calc are great here because you can do something like this:

<txp:adi_gps /> <!-- to grab all the URL params -->
<txp:adi_calc name="pg" multiply="3" /> <!-- assumes you are showing 3 at a time -->
<txp:smd_query blahblah="yoink" limit="3" offset="?pg">
   // something cool here
</txp:smd_query>

Alternatively if you want to keep your plugin base down you can calculate the offset on the fly inside a smidegeon of PHP. I’d like to improve smd_query’s out-of-the-box pagination so when I get a chance I’ll see if I can give you an option to read the current page and automatically apply the offset based on the limit you have already specified.

EDIT: the next thing to worry about is how to reliably do next/prev inside the container. That’s interesting, can’t think of a neat way to do it without having to employ <txp:article custom id="{ID}"><txp:link_to... /></txp:article_custom> inside your query container. Hmmmm… I need to improve smd_query in this department methinx.

Last edited by Bloke (2009-12-01 10:31:35)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#5 2009-12-01 11:04:05

speeke
Member
From: Bruny Island, Australia
Registered: 2009-03-29
Posts: 161
Website

Re: Section article listing beginning with current day's article

Thanks Bloke, some more stuff to ponder.

Shall keep a look out for any updates you might be able to make to smd_query’s pagination and next/prev links, as I would like to keep my ever growing list of plugins to a minimum, if possible. ;)


“People who value their privileges above their principles soon lose both.”
Dwight D. Eisenhower

Offline

#6 2009-12-01 23:54:34

speeke
Member
From: Bruny Island, Australia
Registered: 2009-03-29
Posts: 161
Website

Re: Section article listing beginning with current day's article

This is what I have so far:

<txp:adi_gps name="pg" quiet="1" />
<txp:adi_calc name="pg" multiply="3" />
<txp:smd_query query="SELECT posted FROM textpattern WHERE section = 'section_name' AND status = 4 AND DATE_FORMAT(posted,'%m-%d') <= DATE_FORMAT(CURDATE(),'%m-%d') GROUP BY posted DESC LIMIT 3">
   <txp:article_custom form="article_list" section="section_name" month="{posted}" limit="1" offset="?pg" />
</txp:smd_query>

The article excerpts are output and formatted as desired. But in order to test the pagination, I am trying to output only one article per page. This isn’t working. I think I have misused offset, but am not sure how to fix this.


“People who value their privileges above their principles soon lose both.”
Dwight D. Eisenhower

Offline

#7 2009-12-02 00:00:19

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,493
Website

Re: Section article listing beginning with current day's article

speeke wrote:

I think I have misused offset, but am not sure how to fix this.

Try adding offset="?pg" to smd_query instead. article_custom won’t accept the ?pg syntax so if it turns out you need to embed that value inside the article_custom as well, you’ll have to do the tag-in-tag dance:

<txp:article_custom offset='<txp:variable name="pg" />' />

The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#8 2009-12-02 00:26:33

speeke
Member
From: Bruny Island, Australia
Registered: 2009-03-29
Posts: 161
Website

Re: Section article listing beginning with current day's article

Added. I get the following error:

Tag error:  <txp:smd_query query="SELECT posted FROM textpattern WHERE section = '?s' AND status = 4 AND DATE_FORMAT(posted,'%m-%d') <= DATE_FORMAT(CURDATE(),'%m-%d') GROUP BY posted DESC LIMIT 3" offset="?pg"> ->  Textpattern Notice: Unknown tag attribute: offset  on line 699

“People who value their privileges above their principles soon lose both.”
Dwight D. Eisenhower

Offline

#9 2009-12-02 00:35:49

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,493
Website

Re: Section article listing beginning with current day's article

speeke wrote:

Added. I get the following error:

Ah, oops, that’ll be for the fictional not-yet-written smd_query with offset attribute *sigh* my bad. Does adding OFFSET ?pg (immediately before or after the LIMIT) to the actual query help?

EDIT: not my night, that probably won’t work either. Drat.

Last edited by Bloke (2009-12-02 00:38:29)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#10 2009-12-02 00:39:05

speeke
Member
From: Bruny Island, Australia
Registered: 2009-03-29
Posts: 161
Website

Re: Section article listing beginning with current day's article

Tag error:  <txp:smd_query query="SELECT posted FROM textpattern WHERE section = '?s' AND status = 4 AND DATE_FORMAT(posted,'%m-%d') <= DATE_FORMAT(CURDATE(),'%m-%d') GROUP BY posted DESC OFFSET ?pg LIMIT 3"> ->  Textpattern Warning: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'OFFSET pg LIMIT 3' at line 1
SELECT posted FROM textpattern WHERE section = 'communique' AND status = 4 AND DATE_FORMAT(posted,'%m-%d') <= DATE_FORMAT(CURDATE(),'%m-%d') GROUP BY posted DESC OFFSET pg LIMIT 3  on line 85

I’ve also changed article_custom to article (as it wasn’t required).

EDIT: I am actually now getting pagination, without the error above, but each article is outputting twice, using:

<txp:adi_gps name="pg" quiet="1" />
<txp:adi_calc name="pg" multiply="1" />
<txp:smd_query query="SELECT posted FROM textpattern WHERE section = '?s' AND status = 4 AND DATE_FORMAT(posted,'%m-%d') <= DATE_FORMAT(CURDATE(),'%m-%d') GROUP BY posted DESC LIMIT 3">
   <txp:article listform="article_list" section="?s" month="{posted}" limit="1" />
</txp:smd_query>

Last edited by speeke (2009-12-02 00:44:01)


“People who value their privileges above their principles soon lose both.”
Dwight D. Eisenhower

Offline

Board footer

Powered by FluxBB