Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2013-01-12 06:58:45
- capatxp
- Member
- Registered: 2013-01-12
- Posts: 21
weighting stories for news site
I’m building a news website.
On the front page right now, it’s just listing articles from newest to oldest, regardless of how IMPORTANT the story might be. (so a BIG NEWS story could wind up being the third link down on the front page, below two minor stories, which would be a bad thing.)
So I’m thinking … mebbe you folks could point me in the right direction so that I can:
1) primarily list stories by day published, from newest to oldest (I guess this already takes place, so it’s already done) and
2) secondarily lists stories by WEIGHT, so a story flagged “important!” that day goes higher than one that is not.
The news site will be updated weekly, let’s say, so a story flagged “important” from last week should be listed below a non-important story from this week.
So for the first week the stories might be listed in this order:
Downtown explodes in giant ball of flame (flagged “important”; published that day at 5 p.m.)
Cute kittens love to drink milk! (published same day at 7 p.m.) (newer story, but ranked lower)
then next week:
City Council votes to annex Canada (flagged “important”)
High school sports team loses game.
Downtown explodes in giant ball of flame
Cute kittens love to drink milk!
Offline
Re: weighting stories for news site
It looks like your site is issue-based (one per week). The easiest way is to introduce two custom fields: issue (say, custom_1
) and weight (custom_2
) that will be assigned by the publisher. Then just call <txp:article />
with sort="custom_1+0" DESC, custom_2+0 DESC, LastMod DESC"
attribute (not tested but should work).
If you prefer more linear date-based structure, it’s more tricky, but feasible too. For example, if weight is still stored in custom_2
field, the following
<txp:article sort="ADDDATE(Posted, custom_2) DESC" />
will keep important articles on the top of the list for (roughly) custom_2
days.
Last edited by etc (2013-01-12 16:32:29)
Offline
#3 2013-01-12 20:16:21
- capatxp
- Member
- Registered: 2013-01-12
- Posts: 21
Re: weighting stories for news site
Thanks etc :)
I shall try that.
Offline
Re: weighting stories for news site
One thing to note if using the sort="custom_1+0"
trick – I’ve used this here and there on some sites and it works a treat, but within an individual article, the link_to_next
and link_to_prev
don’t work as they sort by date.
I’ve found its ok with older
and newer
though, so in article list view paging should be fine.
Offline
#5 2013-01-13 02:02:41
- capatxp
- Member
- Registered: 2013-01-12
- Posts: 21
Re: weighting stories for news site
One easy way to do what I want is to simply set the “Published at” time on the article’s word processing page to a later time for more important stories.
So an important story gets set to 11 p.m. while a minor story gets set to 10 p.m.
What do you think of this method?
Alternately, is there a way to do a sort where the date (with no time stamp, JUST THE DATE) is sorted first, followed by the custom_1 “weight” flag? The goal being listing all stories from a certain day by weight:
So it’ll list ‘em in this order:
Jan 3 story IMPORTANT
Jan 3 story minor
Jan 2 story IMPORTANT
Jan 2 story IMPORTANT
Jan 2 story minor
Offline
#6 2013-01-13 02:14:18
- capatxp
- Member
- Registered: 2013-01-12
- Posts: 21
Re: weighting stories for news site
I’ve got it working on my test site http://www.bozemanfreepress.com/txp/
(just look at the home page; ignore other sections as they’re messed up right now)
but I’m doing something a bit hackish in that I’ve set all the “Published at” timestamps to 12:00:00.
I’m using this tag: <txp:article limit=“5” sort=“Posted desc, custom_1 asc”/>
Is there a clean way to do this so I don’t have to set all the timestamps to 12:00:00?
Offline
Re: weighting stories for news site
is there a reason you are not just using <txp:article limit="5" sort="custom_1 asc, Posted"/>
. I think that this will not need to change the timestamp.
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Re: weighting stories for news site
capatxp wrote:
is there a way to do a sort where the date (with no time stamp, JUST THE DATE) is sorted first, followed by the custom_1 “weight” flag?
<txp:article sort="DATE(Posted) DESC, custom_1 ASC" />
should do it.
Offline
Re: weighting stories for news site
jstubbs wrote:
One thing to note if using the
sort="custom_1+0"
trick – I’ve used this here and there on some sites and it works a treat, but within an individual article, thelink_to_next
andlink_to_prev
don’t work as they sort by date.
You are right, Jonathan, link_to_next
will not work with sort="custom_1+0 DESC, custom_2+0 DESC, LastMod DESC"
, but the reason (as I get it) is not custom_1+0
, but multiple sort axes. For the same reason, it will fail with sort="DATE(Posted) DESC, custom_1 ASC"
. But I have seen a tip that can be used here if needed.
Offline
#10 2013-01-13 21:28:38
- capatxp
- Member
- Registered: 2013-01-12
- Posts: 21
Re: weighting stories for news site
That works :)
thanks!
etc wrote:
capatxp wrote:
is there a way to do a sort where the date (with no time stamp, JUST THE DATE) is sorted first, followed by the custom_1 “weight” flag?
<txp:article sort="DATE(Posted) DESC, custom_1 ASC" />
should do it.
Offline
Re: weighting stories for news site
etc wrote:
You are right, Jonathan,
link_to_next
will not work withsort="custom_1+0 DESC, custom_2+0 DESC, LastMod DESC"
, but the reason (as I get it) is notcustom_1+0
, but multiple sort axes. For the same reason, it will fail withsort="DATE(Posted) DESC, custom_1 ASC"
. But I have seen a tip that can be used here if needed.
I just tried this two days ago on a site I was developing – but only with <txp:article limit="999" sort="custom_2+0">
i.e just one sort method. That works fine with older
and newer
but not link_to_prev
or link_to_next
. So I’m not sure it fails due to multiple sorting?
Offline
Re: weighting stories for news site
jstubbs wrote:
I just tried this two days ago on a site I was developing – but only with
<txp:article limit="999" sort="custom_2+0">
i.e just one sort method. That works fine witholder
andnewer
but notlink_to_prev
orlink_to_next
. So I’m not sure it fails due to multiple sorting?
Multiple sorting will fail, but you are right again, it does not even switch to Posted desc
with sort="custom_2+0"
, but gives something weird. Now that I look at the code again, this is to be expected, so one should probably mention it in the documentation? And probably modify getPrevNext
function to treat complex constructions like this one.
Offline