I'm building an online bookstore and have my inventory sorted into multiple taxonomy categories (i.e. by author, publisher, genre, etc.) The taxonomy menu works great, but there is one thing I need to do:
I've modified the ecommerce package to unpublish an item when it is sold out instead of just displaying "sold out". This is great, because it keeps people from seeing items that are unavailable. However, I need to be able to take it one step further and only display taxonomy terms that have members.
This means that if I have books by author John Doe listed and they sell out, the books become unpublished BUT the taxonomy term is still visible but with nothing in it.
Is there something in the rendering code I can change to make this happen? Possibly some variable I can check, maybe something like
if ( $term->members == 0 )
{
// Skip to the next term and don't render this one.
}Any help would be greatly appreciated. If you want an example of how my site is set up it is at http://www.pulpsource.com.
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | taxonomy_menu-hide_empty_and_display_number_of_nodes_per_term.patch | 1.97 KB | esadot |
| #4 | taxonomy_menu-hide_empty.patch | 1.87 KB | systemparadox |
| #3 | taxonomy_menu-hide_empty.patch | 1.86 KB | systemparadox |
Comments
Comment #1
Sophia commentedI would be very interested in that as well :)
Comment #2
designcrs commentedHi!
did anyone of you find a solution yet?
Chris
Comment #3
systemparadox commentedWrap the line:
$items[] = array('path' => $path, 'title' => t($term->name),
'weight' => $term->weight);
(at the bottom of function taxonomy_menu_menu- line 64 in my version)
With:
if (taxonomy_term_count_nodes($term->tid) != 0) {
This works correctly with nested terms. However, it will not hide empty vocabularies altogether. This might actually be useful in some circumstances, and you can manually hide the vocab in the configuration anyway.
A patch is attached with a option for this added to the configuration page.
Comment #4
systemparadox commentedOoops! Config option in the patch was backwards. Not quite sure how I didn't notice that before. Fixed in this version.
Comment #5
designcrs commentedCould anyone check this in so that this feature can be used at least with the latest CVS head version? That'd be great! :-)
How can I apply the patch without having to run CVS on my own? (E.g. using some texteditor that can handle patch files?!)
Thanks!
Comment #6
esadot commentedIt seems to work here.
On a different note, does anyone know how to display the number of items per category name?
For instance, if we have color taxonomy, that would be render in the menu as:
blue (3)
red (15)
green (6)
.
.
Comment #7
systemparadox commenteddesignchris,
Download current version (you don't need to use CVS, just grab the snapshot).
Unpack module to modules dir.
cd modules/taxonomy_menu
patch < taxonomy_menu-hide_empty.patch
Comment #8
esadot commentedI added "display number of nodes per term". The attach comprise both changes.
Comment #9
designcrs commentedsystemparadox,
thanks for the hint.
I've already downloaded the latest snapshot and also the patch file. The remaining question for me is how to get the "patch" program you are using for the command "patch < taxonomy_menu-hide_empty.patch"?
thanks again,
chris
Comment #10
bartoki commentedThis patch works great!
designchris, check out Drupal's Patching Info. On a mac I use the app terminal. I'm sure Windows also has some sort of command line something or other.
Comment #11
brmassa commentedGuys,
im a new maintainer and i just launched the new version of the module. it now has this feature.
regards,
massa
Comment #12
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.