Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-11-06 17:06:47

Neko
Member
Registered: 2004-03-18
Posts: 458

Select latest 10 articles, then display only 1 of them

Hi. As the title suggests, I’d like to have TXP select the latest 10 articles, and display only one of them (random).

I was playing around with article_custom but then I realized I’m not able to figure out how to achieve such a result. Any suggestion, please?

Thanks.

Offline

#2 2009-11-06 17:29:09

MattD
Plugin Author
From: Monterey, California
Registered: 2008-03-21
Posts: 1,254
Website

Re: Select latest 10 articles, then display only 1 of them


My Plugins

Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker

Offline

#3 2009-11-06 20:20:30

Neko
Member
Registered: 2004-03-18
Posts: 458

Re: Select latest 10 articles, then display only 1 of them

Matt,

first of all, thanks for your answer.

I was trying to figure out how to use smd_r_t but I was able to pull the article ID only, and I don’t know how to ask for the latest 10 articles anyway.

<txp:smd_random_text type="database"
     source="textpattern|ID" limit="1"
     wraptag="ul" break="li" />

Should I use that code in conjunction with other tags, such as txp:variable?

On a side note, Stef posing as Einstein is way too cool. XD

Offline

#4 2009-11-06 20:46:13

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Select latest 10 articles, then display only 1 of them

Word, offset.

<txp:article_custom limit="1" offset='<txp:php> echo rand(0,10); </txp:php>' sort="ID desc">
	<!--
		My article
	-->
</txp:article_custom>

Last edited by Gocom (2009-11-06 20:48:06)

Offline

#5 2009-11-06 20:46:23

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

Re: Select latest 10 articles, then display only 1 of them

<txp:article_custom limit="10" sort="posted desc" /><txp:article_id /></txp:article_custom>

Put this inside the smd_random_text tag (probably as the source value, don’t know it) which itself is used as an article tag’s id value (with limit=“1”).


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

Offline

#6 2009-11-06 21:04:03

MattD
Plugin Author
From: Monterey, California
Registered: 2008-03-21
Posts: 1,254
Website

Re: Select latest 10 articles, then display only 1 of them

I’ve used smd_random_text with a txp:variable filled with delimeted text which could be articles.


My Plugins

Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker

Offline

#7 2009-11-06 21:31:19

Neko
Member
Registered: 2004-03-18
Posts: 458

Re: Select latest 10 articles, then display only 1 of them

OK, thanks to all of you for your insightful tips.

I decided to go with Gocom’s suggestion since it’s the easier to implement, at least for me. Thanks!

<txp:article_custom section="Videogiochi, Merendine, Cavolate, Carta, Cartoni-animati, Cinema, Televisione, Giapponeserie, Animali" limit="1" offset='<txp:php> echo rand(0,9); </txp:php>' sort="ID desc">
<a href="<txp:permlink />" title="<txp:title />"><txp:article_image /></a><a href="<txp:permlink />" title="<txp:title />"><span><txp:title /></span></a>
</txp:article_custom>

You can check out the result here (the little framed picture on top right, CSS might bomb in IE).

On a side note: do you notice some flickering while hovering the mouse on the main 8 images? I get that a lot using FF/Mac. Weird, tho, since the same (static) page on the same server using the same browser looks OK to me: http://www.numerozero.it/index.html.

Last edited by Neko (2009-11-06 21:38:34)

Offline

#8 2009-11-06 22:43:21

MattD
Plugin Author
From: Monterey, California
Registered: 2008-03-21
Posts: 1,254
Website

Re: Select latest 10 articles, then display only 1 of them

I think you went with the best solution. I like it and it still looks good in IE7.

The main images have a onhover but it only works for me when I hover over the right border. If my mouse enters the image from any other side the hover doesn’t appear.


My Plugins

Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker

Offline

#9 2009-11-07 22:22:43

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

Re: Select latest 10 articles, then display only 1 of them

Neko wrote:

Weird, tho, since the same (static) page on the same server using the same browser looks OK to me: http://www.numerozero.it/index.html.

Neko, the a-tags inside you h2 don’t have titles on the static HTML site (actually they’re just empty). And that’s what causes the flickering (FF3.5mac here, too): As soon as the titles vanish FF rebuilds the red semi-opaque rectangles.


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

Offline

#10 2009-11-08 01:38:20

Neko
Member
Registered: 2004-03-18
Posts: 458

Re: Select latest 10 articles, then display only 1 of them

Matt and Uli: thanks a bunch for the feedback. I got rid of the tiny JS code for those elements and I’m experimenting a bit with a CSS-only solution. It works fine on FF and Safari so far. No luck on IE, but the JS thing wasn’t working either so I guess it could not be considered a regression. :)

Offline

Board footer

Powered by FluxBB