Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2011-03-01 19:28:07
- bmwg
- Member
- Registered: 2010-04-06
- Posts: 39
check if article exists / display dummy if not
I use the following code to display the 3 most recent news on my startpage:
<ul>
<li><txp:article_custom form="newsForm" category="news" limit="1" /></li>
<li><txp:article_custom form="newsForm" category="news" limit="1" offset="1"/></li>
<li><txp:article_custom form="newsForm" category="news" limit="1" offset="2"/></li>
</ul>
How do I make sure a dummy <li> item gets displayed, when there are no 3 recent news? I don’t want to have empty spots on the page, so I need 3 <li> items for the layout, even if I don’t have enough articles.
Offline
Re: check if article exists / display dummy if not
Hi bmwg,
Not sure what you are trying to achieve (apart from the extra li
) can you post the content of newsForm
?
I cannot understand for example why
<txp:article_custom form="newsForm" category="news" limit="3" wraptag="ul" break="li" />
would not work. After the third post in the news category all will be as you want it… Will it not?
Last edited by colak (2011-03-01 19:56:52)
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
#3 2011-03-01 20:26:37
- bmwg
- Member
- Registered: 2010-04-06
- Posts: 39
Re: check if article exists / display dummy if not
The news are getting deleted when they are not new anymore. Like special prices for a certain time or stuff like that. I don’t want a news-history, but only display up to 3 articles that are active at the moment. So quite often I will have less than 3 articles. But I still want 3 <li> tags. newsForm just displays date, title and excerpt of the article.
Offline
#4 2011-03-01 21:49:50
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: check if article exists / display dummy if not
Wouldn’t it be better to use Yiannis’ tag example and wrap it in a div with a fixed height, than having empty <li></li>
tags on your page?
Offline
#5 2011-03-01 22:33:27
- bmwg
- Member
- Registered: 2010-04-06
- Posts: 39
Re: check if article exists / display dummy if not
Yiannis code is just a more elegant version of mine, right?
Anyway, I have some kind of grid layout and the <li> are white blocks (with margins) on my page. The whole thing is actually wrapped in a div with a fixed size. But I still want 3 seperate white blocks, even if there’s less than 3 articles. Otherwise I get blank spots on my page where the background-pattern shows, which looks funny and destroys my grid.
Isnt’ there a way to count the articles of the news category and display dummy <li> items if the count is less than 3?
Offline
#6 2011-03-01 23:37:29
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: check if article exists / display dummy if not
bmwg wrote:
<ul>
<li><txp:article_custom form="newsForm" category="news" limit="1" /></li>
<li><txp:article_custom form="newsForm" category="news" limit="1" offset="1"/></li>
<li><txp:article_custom form="newsForm" category="news" limit="1" offset="2"/></li>
</ul>
How do I make sure a dummy <li> item gets displayed, when there are no 3 recent news? I don’t want to have empty spots on the page, so I need 3 <li> items for the layout, even if I don’t have enough articles.
Your code will output <li></li>
if there is no article. If they don’t display how you want, maybe you need to give them a width and/or height in your css.
Last edited by els (2011-03-01 23:38:39)
Offline
Re: check if article exists / display dummy if not
That’s a Textpattern feature not a bug :) Content and presentation are separated on purpose.
You need to define the presentation via positioned (background) placeholders in your CSS.
Get all online mentions of Textpattern via OPML subscription: TXP Info Sources: Textpattern RSS feeds as dynamic OPML
Offline