Page 1 of 1

Condition to check for number of news articles in specified category?

Posted: Tue Jan 22, 2008 2:31 pm
by rakim81
I'm looking for some code that will check to see if there are any active news articles in a specified category, and only display a DIV element and its contents if news articles exist.
Any ideas? I guess I need an if statement to check for something, but I don't know what. I have searched the documentation and these forums but not found any.

Re: Condition to check for number of news articles in specified category?

Posted: Tue Jan 22, 2008 3:06 pm
by calguy1000
you mean display a list of categories and only display the category if there are articles in it,

or do you want to display a whole bunch of articles, and group them by category, and only output the category header stuff if there are articles for the category?

Re: Condition to check for number of news articles in specified category?

Posted: Wed Jan 23, 2008 3:37 pm
by rakim81
Ah, sorry I haven't explained this very well at all. basically I only want to display an element of the web page if news articles in a particular category exist. To put it in context, my template has a div positioned in the corner of the page that contains current job vacancies (news articles posted under category 'jobs') - however I would like the div to only appear on the page if there is an actual current job vacancy.

So basically i'd the template might look a little like this in awful pseudo code:

Code: Select all

</__body>
<div id =content>
{content}
</div>
if NUM_OF_ARTICLES > 0
{
<div id = newsbox>
{news number='1' detailpage='news-detail' summarytemplate='frontpage'}
</div>
<__body>
}
else {
<__body>
}
Is this possible?

Re: Condition to check for number of news articles in specified category?

Posted: Wed Jan 23, 2008 3:48 pm
by calguy1000
simple:

capture the output of the news call to a smarty variable, and test if it's empty, (you may need to use a different very simple news summary template for this).

Code: Select all

{capture assign='newscontent'}{news number=1 category='jobs' summarytemplate='baretemplate'}{/capture}
{if !empty($newscontent)}
   {* there is a job *}
   {$newscontent}
{/if}

Re: Condition to check for number of news articles in specified category?

Posted: Thu Jan 24, 2008 3:31 pm
by rakim81
Thanks calguy1000, that capture function is exactly what i was trying to find.