Does anyone know how to limit a category field. Normall with a channel tag I can add limit=“1” and it works fine. Doesn’t seem to work with the category tag. Any Ideas?
This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.
The active forums are here.
January 20, 2011 2:56pm
Subscribe [6]#1 / Jan 20, 2011 2:56pm
Does anyone know how to limit a category field. Normall with a channel tag I can add limit=“1” and it works fine. Doesn’t seem to work with the category tag. Any Ideas?
#2 / Jan 20, 2011 3:04pm
#3 / Jan 21, 2011 2:27am
Thanks lebisol. Does that helpLCBC Church?
#4 / Jan 21, 2011 10:46am
For some reason the limit=“1” method doesn’t seem to be working. It is listing all the categories in the group I designated.
#5 / Jan 21, 2011 11:26am
Here’s the code in question:
{exp:channel:categories channel="gathering" category_group="5" limit="1"}
<a href="http://{homepage}media/cat/{url_title}">{series-ad}</a>
{/exp:channel:categories}My version of EE is: v2.1.1
Any help you can provide would be helpful, thanks!
#6 / Jan 21, 2011 11:28am
And here is the page I am talking about, http://www.lcbcchurchblogs.com/resources/cat/all-church/, the ads on the right column that are square with rounded corners. Only “Preachers, serial killers and me” should be showing.
#7 / Jan 21, 2011 3:26pm
Have you tried something like this?
{exp:channel:categories channel="gathering" category_group="5"}
{if count == 1}
<a href="http://{homepage}media/cat/{url_title}">{series-ad}</a>
{/if}
{/exp:channel:categories}Should basically show the same output compared to using limit=“1” (which is not a valid paramater looking at the docs).
#8 / Jan 21, 2011 3:45pm
Brilliant! That worked, though it feels like a bit of a hack. Does “limit” not work with the categories tag?
#9 / Jan 21, 2011 3:46pm
Brilliant! That worked, though it feels like a bit of a hack. Does “limit” not work with the categories tag?
#10 / Jan 21, 2011 3:56pm
Glad it helped 😊
It’s not a hack, but in this case, it’s not the “best” solution because it fetches all categories for category group with ID 5..loops through all of them and then only displays the first category from that list.
This would be better. If you know the category ID for the ad you’d like to display, you can use this:
{exp:channel:categories channel="gathering" category_group="5" show="3"}
<a href="http://{homepage}media/cat/{url_title}">{series-ad}</a>
{/exp:channel:categories}Now, it will only fetch the category with ID 3 from the category group with ID 5, so it’s more efficient, especially if there are a lot of categories in that category group.
The limit paramater doesn’t exist for the exp:channel:categories tag, as you can see here:
http://ellislab.com/expressionengine/user-guide/modules/channel/categories.html#parameters
There are always several methods to achieve what you want with EE, which is a good thing! 😊
Cheers,
Leon
#11 / Jan 21, 2011 4:05pm
Huh, it’s frustrating that the limit parameter isn’t included with the categories tag. That would have solved everything here. I really just need to display the most recent category. I guess if I had to do the site over again I would use a channel instead of category for our sermon series. Categories just seemed to make more sense when thinking about it at first. Thanks again for the quick response, this issue was driving me nuts!
#12 / Jan 21, 2011 5:38pm
...it’s frustrating that the limit parameter isn’t included with the categories tag
Why would it be? You are presenting entries and there IS a parameter to limit number of entries that will return.
If you know what the category you want then you can just hand pick its ID (and you do not need category group specified since every cat has unique ID)...and done, no need for IF statement.
Channels (old weblogs) vs. Categories is one of the first questions to be answered when planning the site…I know it doesn’t help now but for feature reference here is a link.
#13 / Jan 23, 2011 2:08pm
Hi LCBC Church,
Glad that you got this sorted out. Please post back if required.
@Leon, lebisol, thanks very much for the help.
Cheers
Greg