Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2010-06-26 16:18:53

masa
Member
From: North Wales, UK
Registered: 2005-11-25
Posts: 1,095

Listing a fixed number of articles but excluding expired ones

I want to list the 5 most recent news items on a front page, except if they’re expired. My form looks like this:

<txp:if_expired>
<txp:else />
<p class="news"><txp:permlink><txp:posted format="%d.%m.%Y" />: <txp:title /></txp:permlink></p>
</txp:if_expired>

That works fine except for one little detail: if there are 2 expired articles amongst the 5 most recent, only 3 articles are listed.

However in that case I would like any older articles to move up and fill the vacant slots, so the list would always display 5 articles.

Any tips would be much appreciated.

PS: here’s the article tag calling the above form…

<txp:article_custom section="news" limit="5" form="article_newsline" />

Last edited by masa (2010-06-26 16:22:30)

Offline

#2 2010-06-26 16:52:19

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,315

Re: Listing a fixed number of articles but excluding expired ones

Martin, reminds me of this post by Stef I once bookmarked in a thread named How can I limit the number of returned Articles when limit= won’t do?. Hope it does what you want :)

Last edited by uli (2010-06-26 17:15:02)


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#3 2010-06-26 18:20:16

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: Listing a fixed number of articles but excluding expired ones

Have a look at soo_article_filter.


Code is topiary

Offline

#4 2010-06-27 00:11:46

masa
Member
From: North Wales, UK
Registered: 2005-11-25
Posts: 1,095

Re: Listing a fixed number of articles but excluding expired ones

Thanks Uli and Jeff!

Uli, that definitely looks like it’s got the right bits in it, but man, it does look complicated. All those tags, nesting and plugins I’ve never used :)
Will see, whether I can get my head wrapped around that.

Jeff, I had a look at the plugin’s documentation and I have a question. If I were using <txp:soo_article_filter expires="0"> that would simply exclude all articles with an expiry date set, no matter whether that date had been passed or not, right?

Last edited by masa (2010-06-27 00:14:04)

Offline

#5 2010-06-27 00:54:13

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: Listing a fixed number of articles but excluding expired ones

masa wrote:

Jeff, I had a look at the plugin’s documentation and I have a question. If I were using <txp:soo_article_filter expires="0"> that would simply exclude all articles with an expiry date set, no matter whether that date had been passed or not, right?

Correct. And looking more closely at your request, I see that there are some useful combinations my plugin does not provide for, such as the case where you want only non-expired articles, including articles without an expiry date set. Is that what you need?


Code is topiary

Offline

#6 2010-06-27 01:23:50

masa
Member
From: North Wales, UK
Registered: 2005-11-25
Posts: 1,095

Re: Listing a fixed number of articles but excluding expired ones

jsoo wrote:

And looking more closely at your request, I see that there are some useful combinations my plugin does not provide for, such as the case where you want only non-expired articles, including articles without an expiry date set. Is that what you need?

Yes, exactly.

Say, if I had a list of articles like so…

  1. posted 1. June – expires 15. July
  2. posted 1. May – no expiry
  3. posted 1. April – expires 15. May
  4. posted 1. March – no expiry
  5. posted 1. February – no expiry
  6. posted 1. January – expires 15. February
  7. posted 1. December – no expiry
  8. posted 1. November – no expiry
  9. posted 1. October – no expiry
  10. etc.

When someone visits the site now, 27. June, I’d like to show…

  1. posted 1. June – expires 15. July
  2. posted 1. May – no expiry
  3. posted 1. March – no expiry
  4. posted 1. February – no expiry
  5. posted 1. December – no expiry

…omitting the January and April posts since they are expired and older articles move up.

Offline

#7 2010-06-27 01:40:52

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: Listing a fixed number of articles but excluding expired ones

OK, I’ll think about how to update the plugin to handle this — a useful case.

Edit: And just to be clear, I assume this is for a site with Publish expired articles? set to Yes? Or does article_custom ignore this preference?

Last edited by jsoo (2010-06-27 02:02:09)


Code is topiary

Offline

#8 2010-06-27 02:06:35

masa
Member
From: North Wales, UK
Registered: 2005-11-25
Posts: 1,095

Re: Listing a fixed number of articles but excluding expired ones

jsoo wrote:

And just to be clear, I assume this is for a site with Publish expired articles? set to Yes?

Yes, that prefs setting is enabled.

Offline

#9 2010-06-27 11:44:43

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: Listing a fixed number of articles but excluding expired ones

Actually, then, I think the best solution is to change the preference setting temporarily:

<txp:php>
    global $prefs;
    $prefs['publish_expired_articles'] = 0;
</txp:php>
<txp:article_custom section="news" limit="5" form="article_newsline" />
<txp:php>
    global $prefs;
    $prefs['publish_expired_articles'] = 1;
</txp:php>

No plugin required. You can skip the second php block if there are no article tags later on the page (and for which you want the original setting in effect).

Setting preferences in this way is temporary and has no effect on the settings stored in the DB, only for the current page.


Code is topiary

Offline

#10 2010-06-27 16:47:48

monkeyninja
Plugin Author
From: Sheffield, UK
Registered: 2008-10-14
Posts: 239
Website

Re: Listing a fixed number of articles but excluding expired ones

I’ve got a little plugin that does this that I put together for a project that needed something very similar to this. In your case all you’d need to do is the following:-

<txp:arc_pref_override pref="publish_expired_articles" value="0">
  <txp:article_custom section="news" limit="5" form="article_newsline" />
</txp:arc_pref_override>

Offline

#11 2010-06-27 17:48:04

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: Listing a fixed number of articles but excluding expired ones

Thanks, I was wondering if there were such a plugin; I failed to find it on a quick search.


Code is topiary

Offline

#12 2010-06-27 17:50:23

monkeyninja
Plugin Author
From: Sheffield, UK
Registered: 2008-10-14
Posts: 239
Website

Re: Listing a fixed number of articles but excluding expired ones

jsoo wrote:

Thanks, I was wondering if there were such a plugin; I failed to find it on a quick search.

It’s one of those little things that I hadn’t got round to putting out there on the web, but this thread prompted me. Hope others find it of some use.

Offline

Board footer

Powered by FluxBB