EllisLab text mark
Advanced Search
     
Display category on single entry page
Posted: 15 November 2010 06:04 PM
Joined: 2010-07-19
36 posts

I’d like to list the categories an entry is posted in. If no categories have been selected, I’d like it to say “None” or not show the category section all together. Using if no_results doesn’t seem to work.

My code is below (and doesn’t work):

<strong>Category:</strong{categories backspace="2"}{if no_results}None{if:else}{category_name}{/if}{/categories} 
 
Posted: 15 November 2010 06:46 PM   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2008-02-29
777 posts

The categories loop doesn’t have a no_results conditional, so that won’t work.

There is a plugin available for EE1 called Category Count, but it hasn’t been ported to EE2 yet.

I could check and see if I can whip something up as I don’t think it should be hard to create something for EE2.

Greetz,
Wouter

 Signature 

Baseworks Webdevelopment


Twitter | GitHub | Devot:ee | LinkedIn

 
Posted: 15 November 2010 06:53 PM   [ # 2 ]   [ Rating: 0 ]
Joined: 2010-07-19
36 posts

Yeah, I’m on EE2. If you wouldn’t mind putting something together real quick, that’d be great!

 
Posted: 15 November 2010 07:46 PM   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2008-02-29
777 posts

As promised, here’s a quick extensions to do what you need and you can get it from GitHub.

Just install the add-on and it adds a {category_count} variable to the available variables in the {exp:channel:entries} loop.

{exp:channel:entries channel='lorem'}
  {if category_count 
== 0}None{if:else}{categories backspace='2'}{category_name}{/categories}{/if}
{
/exp:channel:entries} 

I haven’t tested it extensively, but this add-on is so simple it couldn’t break that much.

Greetz,
Wouter

 Signature 

Baseworks Webdevelopment


Twitter | GitHub | Devot:ee | LinkedIn

 
Posted: 15 November 2010 07:47 PM   [ # 4 ]   [ Rating: 0 ]
Joined: 2010-07-19
36 posts

Awesome, thank you!

 
Posted: 15 November 2010 07:56 PM   [ # 5 ]   [ Rating: 0 ]
Avatar
Joined: 2008-02-29
777 posts

Does it work for you?

 Signature 

Baseworks Webdevelopment


Twitter | GitHub | Devot:ee | LinkedIn

 
Posted: 16 November 2010 08:26 AM   [ # 6 ]   [ Rating: 0 ]
Avatar
Joined: 2002-04-29
26055 posts

Thanks for the assist, Wouter!

fouroakschurch, does Wouter’s add-on help?

 
Posted: 30 November 2010 05:08 PM   [ # 7 ]   [ Rating: 0 ]
Avatar
Joined: 2009-03-15
71 posts

Working great for me! Thank you so much!

 Signature 

Brian Kalwat

 
Posted: 01 December 2010 07:49 AM   [ # 8 ]   [ Rating: 0 ]
Avatar
Joined: 2002-04-29
26055 posts

Glad to hear it Brian.

fouroakschurch, what about you?