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

General project discussion. NOT for help questions.
Post Reply
rakim81
New Member
New Member
Posts: 3
Joined: Tue Jan 22, 2008 2:15 pm

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

Post 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.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

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

Post 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?
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
rakim81
New Member
New Member
Posts: 3
Joined: Tue Jan 22, 2008 2:15 pm

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

Post 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?
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

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

Post 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}
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
rakim81
New Member
New Member
Posts: 3
Joined: Tue Jan 22, 2008 2:15 pm

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

Post by rakim81 »

Thanks calguy1000, that capture function is exactly what i was trying to find.
Post Reply

Return to “General Discussion”