Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#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
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
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…
- posted 1. June – expires 15. July
- posted 1. May – no expiry
- posted 1. April – expires 15. May
- posted 1. March – no expiry
- posted 1. February – no expiry
- posted 1. January – expires 15. February
- posted 1. December – no expiry
- posted 1. November – no expiry
- posted 1. October – no expiry
- etc.
When someone visits the site now, 27. June, I’d like to show…
- posted 1. June – expires 15. July
- posted 1. May – no expiry
- posted 1. March – no expiry
- posted 1. February – no expiry
- posted 1. December – no expiry
…omitting the January and April posts since they are expired and older articles move up.
Offline
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 toYes
?
Yes, that prefs setting is enabled.
Offline
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
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
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
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