WordPress: Conversational Categories
A friend asked if there was a way for WordPress to display the categories under which an entry is filed in the following way:
Single category: Category1
Two categories: Category1 and Category 2
Three categories: Category1, Category2 and Category3
Four categories: Category 1, Category 2, Category 3 and Category 4
And so forth.
The existing the_category() function has no way of telling how many categories there are, and so can’t do something fancy like inserting the word “and” between the penultimate (second-to-last) and ultimate categories. So I just made a plugin with a new function called the_nice_category().
Download
WordPress Nice Categories Plugin (WP 1.5.1 and above)
Instructions
Go ahead and save this text as a file with a “.php” extension, and drop it in your plugin folder. After activating it, you will be able to use a new function in your WordPress template. The function is the_nice_category(). You will replace the instance of the_category() with the_nice_category() in the “posted” section of your main index file.
the_nice_category() takes two optional parameters. The first is the text string to appear between categories when the category on the right isn’t the last category. This defaults to “, ” (a comma and a space). The second parameter is the text string to appear between the penultimate category, and the last category. This defaults to ” and ” (the word “and” buffered by spaces.)
If you wanted to display your categories like the default, but with double quotes around them, you would use this code:
"<?php the_nice_category(', "', '" and "'); ?>"
Notice that you need to place quotes on either side of the_nice_category(). This is to put the quotes at the beginning of the first category, and at the end of the last category.
Notes
Also, if you want to determine if there are multiple categories, you can do so by using count(get_the_category()).
This code will output “Category: ” if there is only one category, and “Categories: ” if there are more than one.
<?php if (count(get_the_category()) > 1) echo 'Categories: '; if (count(get_the_category()) === 1) echo 'Category: '; ?>
Versions
- version 1.5.1, updated for WordPress 1.5.1 compatibility.
- version 1.5, updated for WordPress 1.5 compatibility.
- version 1.1, merged in updated WP 1.3 the_category() code (only change is that it won’t throw out an error if there are no categories for that entry). Should work fine with WordPress 1.2 as well.
- version 1.0, the initial release.
Why do we love the darkness and the moonlight? My dear, you need only look into your own unliving desires to find out.
——————————————–
electronics
antivirus
[...] Nice Categories: Muestra las categorÃas asociadas a la entrada de forma conversacional, en lugar de en forma de lista, por ejemplo: CategorÃa1, CategorÃa2 y CategorÃa3. [...]
[...] The Conversational Categories and Admin Controls are based of the plugins Nice Categories by Mark Jaquith, and WP Admin Bar 2 by Matt [...]
You can download Versa 0.4.4 in a zip-file. You can checkout the SVN repository located at http://svn.workspaceconsult.com/versa/ Be aware that currently the theme relies on two plugins – Clean Archives Reloaded and Nice Categories. Your choice. Use at your own discretion and risk. Any bugs, comments, suggestions and such can be left in the comments. [IMG Creative Commons License]
nice, very nice. i like it more. i’ve install on my blog. thank’s
[...] Conversational Categories [...]
Nice Categories. Thanks to Liquid, I can do the same without a plugin. In your default article template, it would be: {% for tag in article.tags %} {% if forloop.length == 1 %} {{ tag | link_to_tag }} {% elsif forloop.length == 2 %} {% if forloop.last %} and {{ tag |
12:54AM *Mephisto-Fu — Nice Tags I’m silly. I like my tags to read: tag_one, tag_two and tag_three Instead of: tag_one, tag_two, tag_three When I used WordPress, I used a plugin called Nice Categories. Thanks to Liquid, I can do the same without a plugin. In your default article template, it would be: {% for tag in article.tags %} {% if forloop.length == 1 %} {{ tag | link_to_tag }} {% elsif forloop.length == 2 %} {% if forloop.last %} and {{ tag |
Nice plugin you have going here. I will check it out and test it on my weblog.
[...] Nice Categories: Muestra las categorÃas asociadas a la entrada de forma conversacional, en lugar de en forma de lista, por ejemplo: CategorÃa1, CategorÃa2 y CategorÃa3. [...]
[...] Visit [...]
[...] Visit [...]
[...] Visit [...]
[...] Conversational Categories [...]
I installed the plugin in the Plugins directory and activated it. Then I just needed to do some minor modifications to my theme files to get it to display the categories nicely. Picked the plugin up from txfx.net at this page. Share This
[...] Nice Categories: Muestra las categorÃas asociadas a la entrada de forma conversacional, en lugar de en forma de lista, por ejemplo: CategorÃa1, CategorÃa2 y CategorÃa3. [...]
[...] Nice Categories [...]
[...] uploadFlickr Photo GalleryGoogle SitemapsGravatarLast.Fm RecordsMint Popular PostsNice CategoriesRelated PostsSearch EverythingsIFR TitlesWP lightbox [...]
[...] Nice Categories [...]
[...] Nice Categories v1.0 [...]
[...] Nice Categories [...]
very nice
thanks for this plugin
[...] pero ha sido por la falta de documentación sobre el tema: la página del plugin no existe, el post de donde me bajé la versión anterior es de 2004 y no está actualizado, no hay instrucciones para [...]
[...] Dunstan’s Time Since http://www.neato.co.nz/ultimate-tag-warrior/: Ultimate Tag Warrior 3 http://txfx.net/2004/07/22/wordpress-conversational-categories/: Conversational Categories http://www.skippy.net/blog/category/wordpress/plugins/wp-db-backup/: [...]
[...] Nice Categories: Muestra las categorías asociadas a la entrada de forma conversacional, en lugar de en forma de lista, por ejemplo: Categoría1, Categoría2 y Categoría3. [...]
[...] Nice Categories: Muestra las categorías asociadas a la entrada de forma conversacional, en lugar de en forma de lista, por ejemplo: Categoría1, Categoría2 y Categoría3. [...]
[...] the category links for posts are broken, Ill have to have a look when I get home.Fixed now, new Conversational Categories plugin for [...]
[...] is a WordPress plugin tweaked from wordpress related entries plugin, it also uses portions of the nice categories plugin to list the related posts – comma separated with ‘and’ before the last in the same whay that nice [...]
[...] Nice Categories: Muestra las categorías asociadas a la entrada de forma conversacional, en lugar de en forma de lista, por ejemplo: Categoría1, Categoría2 y Categoría3. [...]
[...] Nice Categories [...]
[...] Nice Categories [...]
[...] Nice Categories: Muestra las categorías asociadas a la entrada de forma conversacional, en lugar de en forma de lista, por ejemplo: Categoría1, Categoría2 y Categoría3. [...]
[...] Nice Categories: Muestra las categorías asociadas a la entrada de forma conversacional, en lugar de en forma de lista, por ejemplo: Categoría1, Categoría2 y Categoría3. [...]
[...] Nice Categories: Muestra las categorías asociadas a la entrada de forma conversacional, en lugar de en forma de lista, por ejemplo: Categoría1, Categoría2 y Categoría3. [...]
[...] Nice Categories: Muestra las categorías asociadas a la entrada de forma conversacional, en lugar de en forma de lista, por ejemplo: Categoría1, Categoría2 y Categoría3. [...]
[...] Nice Categories [...]
[...] Nice Categories: Muestra las categorías asociadas a la entrada de forma conversacional, en lugar de en forma de lista, por ejemplo: Categoría1, Categoría2 y Categoría3. [...]
http://yaycacudby.livejournal.com/ -