Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
check if there is articles in category
I’m doing site for theatre, and I have articles in categories “playing_now”,“upcoming” and “old_plays”. In frontpage I want to show articles from playing_now category with picture and some information, and articles from upcoming category only with small text or something.
But as it is a small theatre there isn’t allways a show playing, so in that situation i would like show articles from upcoming category with images and more information.
So is there some tag or plugin what i could use like this:
< if articles_in_category playing_now >
show Playing_now articles with pictures and full information
and show upcoming articles with little information and without picture
< else >
show upcoming articles with pictures and full information
Last edited by khellstr (2006-02-28 17:29:52)
Offline
#2 2006-02-28 16:16:34
- frederik
- Member
- From: Denmark
- Registered: 2004-12-08
- Posts: 17
Re: check if there is articles in category
You could probably use this plugin
Offline
#3 2006-02-28 17:40:11
- rsilletti
- Moderator
- From: Spokane WA
- Registered: 2004-04-28
- Posts: 707
Re: check if there is articles in category
These might help: <a href=“http://textcastle.com/article/47/update-on-ifarticle-category”>if_article_category1 and if_article_category2</a>
<a href=“http://textcastle.com/file_download/34”>Plugin Link</a>
Offline
Re: check if there is articles in category
Now i found how to write code to forum posts, its much easier to describe what i need…
I could use chh_if_data, but if there is more than one tag inside the chh_if_data it will evaluate to true when any of the tags returns data. I need to know if tag <txp:article_custom category="playing_now">
evaluates true.
<code>
<txp:chh_if_data >
<txp:article_custom category=“playing_now” form=“picture_and_Excerpt” />
<txp:article_custom category=“upcoming” form=“only_title” />
<txp:else />
<txp:article_custom category=“upcoming” form=“picture_and_Excerpt” />
</txp:chh_if_data>
</code>…
about the if_article_category1 and if_article_category2, I understand these find out if article is in category, but i need to know If there is articles in spesific category. I found some plugins wich calculates the articles in category but they dont work like condition tags.
anyway Thanks for the fast answers, great forum and great sofware.
Last edited by khellstr (2006-02-28 21:11:51)
Offline
#5 2006-02-28 20:34:00
- rsilletti
- Moderator
- From: Spokane WA
- Registered: 2004-04-28
- Posts: 707
Re: check if there is articles in category
The if_article-category1 and 2 tags will look for a specific category, using a comma delimited list for “name” attribute. They look for category matches as a conditional tag. The article link should give you a clearer idea. These are article form tags, they won’t work in a page template.
<code><txp:ras_if_article_category1 name=“playing_now”></code>
<code><txp:article_custom category=“playing_now” form=“picture_and_Excerpt” /></code>
<code></txp:ras_if_article_category1></code>
…
all you need to do is check the article’s category – correct, not the actual output from article_custom?
TXP has a txp:if_article_category tag that works the same way except it looks by category name
and an option level cat1 or cat2 with a number attribute (it won’t handle a list, however).
I would take a look at the <a href=“http://textpattern.net/wiki/index.php?title=Alphabetical_Tag_Listing”>Tag Index</a> in Textbook as well.
Last edited by rsilletti (2006-02-28 20:40:12)
Offline
Re: check if there is articles in category
“all you need to do is check the article’s category – correct, not the actual output from article_custom?”
No, I need to check if there is articles in category “playing_now”.
Offline
#7 2006-02-28 22:26:52
- rsilletti
- Moderator
- From: Spokane WA
- Registered: 2004-04-28
- Posts: 707
Re: check if there is articles in category
Ok – it might help to clarify the context a little.
If you are returning a single article, you need to test to see if the article returned is in category “playing_now”:
What means did you use to return that article?
If you are returning more than one per page.
What means did you use to return those articles?
What are you trying to accomplish by ascertaining the current article’s category? (selecting for display? changing styles?)
—-
You could specify the required category in the article or article_custom tag up front and take care of the need for a conditional.
There is probably a better way to accomplish what you are trying to do than the approach you’re using. The conditionals will test for categories and sections within an article form on an article by article basis; and the current section or category for the present list of articles can be looked at in a page context.
If you use <code><txp:article_custom category=“playing_now” /></code> it will return a list of articles from that category, there is no reason to test for it at that point?
or you could use an arrangement like this (hope its clear what is being done here)
Page template:
<code><txp:article form=“yourform” /></code>
Article form:“yourform”
<code><txp:if_article_category name=“playing_now”></code>
<code> article tags and html go here for playing_now </code>
<code><txp:else /></code>
<code> article tags and html go here for article not of category playing_now </code>
<code></txp:if_article_category></code>
Last edited by rsilletti (2006-02-28 22:46:00)
Offline
Re: check if there is articles in category
Here is a picture what i’m trying to achieve:
all the pictures are from the frontpage, pic 1 have no problem. But if there is nothing to show in “now playing” category, I want the articles from “coming up” category formed “bigger” (as in the PIC 2) not like they are in PIC 3.
Offline
#9 2006-02-28 23:50:49
- rsilletti
- Moderator
- From: Spokane WA
- Registered: 2004-04-28
- Posts: 707
Re: check if there is articles in category
There is an if_first_article tag that tests to see if the current article is the first in the list. If your first article is of category now_showing (you could accomplish this by nesting the conditional example above in the if_first conditional), and use the else clause to set a second set of article components to accomplish the appearance you want as a default when nothing is showing. (I haven’t set out any tags to check this so it may have the same catch-22 as you dealing with now)
The only real hitch may be the need to keep your now showing article at the top of the sort order so it displays first.
The real problem here is that any test that you use for an article, in an article form, will apply to all of them in the list recursively. I can’t think of a category or section page arrangement that would accomplish this either.
Something way fugly in pastebin <a href=“http://pastebin.com/577696”>Article form</a>, it seems to me to be the next step, but you may want to get an opinion from someone better with PHP on variable scope.
I hope I am not missing something obvious here, it just seems that this should be easier.
Last edited by rsilletti (2006-03-01 01:08:07)
Offline
Re: check if there is articles in category
Now i get it work. It uses PHP and mdn_count plugin. Only thing i don’t like is that i have to write my txp and html inside php echo.
<code>
<txp:php>
if (mdn_count(array(“category”=>“now_playing”)) >= 1) {
echo “<txp:article_custom category=‘now_playing’ listform=‘picture_and_Excerpt’/>”
echo “<txp:article_custom category=‘up_coming’ listform=‘only_title’ />”;
}
else {
echo “<txp:article_custom category=‘up_coming’ listform=‘picture_and_Excerpt’ />”;
}
</txp:php>
</code>
Offline
#11 2006-03-03 00:16:34
- rsilletti
- Moderator
- From: Spokane WA
- Registered: 2004-04-28
- Posts: 707
Re: check if there is articles in category
I wasn’t sure if moving in and out of PHP to avoid the echo would break the parser or not, but if what you have works, its certainly straight forward. Very nice.
Offline
Re: check if there is articles in category
Thanks khellstr. This post is very helpful.
Offline
Pages: 1