I've been trying to find a simple way to do this, and it's not easily found.

I want to create a View (either a block or page, I would have application for both) that can list taxonomy terms in a given vocabulary. Unfortunately, I can't figure out a good way to do this.

When I've tried, it's very inconsistant, and prints duplicates of the taxonomy terms (using node: distinct doesn't fix it)

Is there a way to do this?

The application I outlined here would be a good example: http://drupal.org/node/128080#comment-211402 (I didn't realize until after the post, that creating a list of galleries (which are actually taxonomy terms) would be the hard part)

I looked into the Category module (with category views) and it either doesn't do what I want, or I didn't understand it.
Any help/direction here?

Comments

Anonymous’s picture

Maybe I didn't get your problem, but doesn't this work for you:
http://www.Yoursite.Com/?q=directory

It presents me with a nice A (12) B (44) C (17) ... Z (5) list, which, upon clicking, opens the taxonomy terms beginning with that particular letter. But as I said, I don't know if that was your problem...

Ludo

Rob_Feature’s picture

Hey Ludo...
Thanks, but no, that's not what I'm looking for. (maybe I confused you by saying I'd like it in a page too)...

But, i"d like the taxonomy terms (only from a certain vocabulary) to display in a listing...so I can use them in a block.

For example, on our podcast, each 'series' of episodes we do is a taxonomy...I want to do a block listing of all of our series, which means listing those taxonomies. Does anyone know how to do this?

-Bob Christenson
Owner/Designer, Mustardseed Media, Inc.
MustardseedMedia.com

/**
  * Bob Christenson
  * Mustardseed Media
  * http://mustardseedmedia.com
  */
NancyDru’s picture

I get "Access Denied" and I'm logged in as user/1.

Nancy W.
now running 5 sites on Drupal so far
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in Your Database

jastraat’s picture

Do you want the block of taxonomy terms to be related to the node in which the block is displayed?

If not - it might be easier to not use views at all, and just create a block using something like taxonomy_get_tree() for each vocabulary using that vocabulary's vid.

Rob_Feature’s picture

If i understand this right, it might be the answer. I don't know PHP, so i'll have to play around with it, but I think all the info I need is on this page: http://api.drupal.org/api/HEAD/function/taxonomy_get_tree

Do i just format this into a block using PHP and it should list my terms for the vocab I designate?

-Bob Christenson
Owner/Designer, Mustardseed Media, Inc.
MustardseedMedia.com

/**
  * Bob Christenson
  * Mustardseed Media
  * http://mustardseedmedia.com
  */
jastraat’s picture

Bob,
To create a block with php-generated content, go to Administer >> Site building >> Blocks and add a new block. Change the input format to php. I found the following in another post that may be helpful:

$vid = 1;  // Set the vid to the vocabulary id of the vocabulary you wish to list the terms from
$items = array();
$terms = taxonomy_get_tree($vid);
foreach ( $terms as $term ) {  
	$count = db_result(db_query("SELECT COUNT(nid) FROM {term_node} WHERE tid = %d", $term->tid));  
	$items[] = l($term->name, "taxonomy/term/$term->tid") . " ($count)";
}
if ( count($items) ) {  print theme('item_list', $items);}

Once you've created the block, you'll have to enable it in a page region. You can also designate on which pages you'd like the block to appear.

Rob_Feature’s picture

This looks perfect, jastraat. You're my hero.

But, is it just me, or is it strange that Views can't do this? Seems like it would be easy to implement. (Although, on second thought, views is good at listing nodes, but nothing else, sooo...maybe it's the wrong tool).

Anyway, thanks!

-Bob Christenson
Owner/Designer, Mustardseed Media, Inc.
MustardseedMedia.com

/**
  * Bob Christenson
  * Mustardseed Media
  * http://mustardseedmedia.com
  */
jastraat’s picture

Glad to help.

Quint’s picture

Nice and simple solution.

Quint

jiangxijay’s picture

I'm also adding a comment so I can track this solution.

colkassad’s picture

Wow, this is what I was looking for. Thanks. However, the selection does not take into account articles, etc, that are unpublished. For instance, if I have only one story under a certain term, and it's set to unpublished, it still shows up in the list along with the count in parenthesis. Perhaps the SQL could be modified to exclude unpublished articles?

NancyDru’s picture

There are cases where I want it this way, and there are cases where I'd prefer it the "standard" way. Try changing:

$count = db_result(db_query("SELECT COUNT(nid) FROM {term_node} WHERE tid = %d", $term->tid));

to:

$count = db_result(db_query("SELECT COUNT(tn.nid) FROM {term_node} tn JOIN {node} n USING (nid) WHERE tid=%d AND n.status=1", $term->tid));

This is untested, but should be real close.

Nancy W.
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in your database

colkassad’s picture

Great! That seems to work. Thank you, Nancy!

NancyDru’s picture

skyredwang’s picture

Thanks for your information and work.

NancyDru’s picture

I have now taken over the Taxonomy List module and some of those things are gradually working their way into the code.

Nancy W.
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in your database

Didaci’s picture

Hello,

I updated from 4.5.3 to 5.3 and i got the same problem, my categories block disappeared.

Your code fix it but would be posible to order it with the last updated term? And would be posible to show the last updated in days, hours, minutes ( examples: 1 years 11 weeks ago , 1 days 16 hours ago)?

Thanks.

NancyDru’s picture

Taxonomy does not keep track of when terms are added. It could be added with a module, but apparently there are few people who want it.

Formatting intervals is easy: http://api.drupal.org/api/function/format_interval/5

Nancy W.
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in your database

pierrelord’s picture

Thanks!

excell’s picture

I have spent an entire day trying to figure out how to acheive this - generate a block with the terms for the category selections for a section! Two seconds of work and your answer is implemented and working! I had tried everything, searched many places and was totally frustrated.

Only thing I had to do was to add the code for if the term was empty and luckly I had a person with php knowledge available...
Just adding the line:

if ($count)

above the line: $items[] = l($term->name, "taxonomy/term/$term->tid") . " ($count)";

and - PERFECT!
Thanks sooooo much for sharing...

mz906’s picture


$vid = 1;  // Set the vid to the vocabulary id of the vocabulary you wish to list the terms from
$items = array();
$terms = taxonomy_get_tree($vid);
foreach ( $terms as $term ) { 
    $count = db_result(db_query("SELECT COUNT(nid) FROM {term_node} WHERE tid = %d", $term->tid)); 
    $items[] = l($term->name, "taxonomy/term/$term->tid") . " ($count)";
}
if ( count($items) ) {  print theme('item_list', $items);}

can you do this using the views UI?

jfall’s picture

this discussion started with bob trying to use Views!
The upshot - Views produces a list of NODES not TERMS, so not really.
That said, here is a little "modulette" (just a packaged snippet) that uses a View to perform the queries - nodes are listed by term, using the View to select and format the node listing under each term.
http://lasqueti.ca/books/design-notes/custom-theme/directory
As a bonus, nodes for each term can optionally be put into collapsible fieldsets and organized into a number of columns to tidy up the display.
Here's an example of what this snippet can do:
http://lasqueti.ca/marketplace/directory
the View is defined to select only nodes that should be displayed in the directory (i.e., it filters out nodes I don't want displayed here) and specifies a Table view type with teaser image + title as link.

mariagwyn’s picture

I am experimenting with this, but am getting an error:
Parse error: syntax error, unexpected T_VARIABLE in .../sites/mariagwyn.com.snqclean/themes/snq/template.php on line 390. This line is the line where I set the variable $vid. I have it set to the correct image vocab, and the directory_view.php file is uploaded, set with require_once ('directory_view.php');

Any ideas?

Thanks,
Maria

NancyDru’s picture

I, personally, can't.

If you want to get even fancier, rather than hard-coding "taxonomy/term/..." the more correct implementation would be:

$items[] = l($term->name, taxonomy_term_path($term->tid)) . " ($count)";

This will allow modules like Taxonomy Redirect to function from your list.

Nancy W.
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in your database

willdashwood’s picture

$items[] = l($term->name, taxonomy_term_path($term)) . " ($count)";

Viranil’s picture

I tried this, and the import views method and neither returned my list. when i go to the /taxonomy/term/# page i see my nodes, but the query in the php code, and in the views approach seems to return nothing.

I like the php approach better because I am very new to the views module.
This way i just change the $vid to my term number and save the block. am i doing something wrong?

daytripscanada’s picture

This has answered my prayers. I does EXACTLY what I needed. I am building a directory of items that are all catagorized, then sub-categorized, then sub-catagorized again where the nodes ONLY exist in the last category. I wanted to allow users to click through categories until they reach the nodes. (Similar to the old Yahoo.com if anyone remembers that far back)

Now.. I've figured out how to use this code and blocks to do it for each subcategories page... but that requires creating a block for each and every cat/subcat. Is there a way to make this work generic so that I only need to create one block and then assign that single block to all my cat/subcat pages.

I guess what I am looking for is something that would set the parent value automatically based on something rather than me making multiple blocks like :

taxonomy_get_tree($vid,1,-1,1);
taxonomy_get_tree($vid,2,-1,1);
taxonomy_get_tree($vid,3,-1,1);
taxonomy_get_tree($vid,4,-1,1);
etc.

NancyDru’s picture

The Taxonomy Context module may do something like that; you can look at it for inspiration.

Nancy Dru (formerly Nancy W. until I got married to Drupal)

johnphethean’s picture

I found the same script in the book pages that jastraat kindly quoted, but there isn't an explanation of how to filter by content type. Has anyone come across this?
Some vocabularies can be used by more than one content type, and I want to just view the list for one of them - is this possible?
Thanks in advance for any help...

NancyDru’s picture

Depending on whether you want to change the code or not. One way is the Node Type Filter module. Also there was a similar request by "summit" I think that I helped him with and it's posted somewhere (possibly in this thread). Here it is: http://drupal.org/node/128085#comment-811814

dreamydell’s picture

2noame’s picture

I didn't want the number in parentheses after everything so I went with putting the following in a block:

<?php
$vid = 1;
$terms = taxonomy_get_tree($vid);
print '<div id="menu"><ul>';
foreach ($terms as $term) {
if ($term->depth == 0) {
print "<li>".l($term->name,'taxonomy/term/'.$term->tid, array('title' => $term->name))."</li>";
}
}
print '</ul></div>';
?>

This displays a simple list of parent terms as links for the vocabulary with vid = 1.

But how would I further modify this to list only parent terms that have more than 0 nodes attached to them?

Ankit22’s picture

I just want to know .... is their any way by which i can skip certain taxonomy terms ?

or may be some way to skip the very first term....

NancyDru’s picture

I've just recently added a new module called Taxonomy Link Mover that might help you. My customer uses it to not show terms from one vocabulary, and the others in alphabetical order.

Ankit22’s picture

Thanks for your reply but taxonomy link mover was of no use to me ... :(
I am using this code


$vid = 10;  // Set the vid to the vocabulary id of the vocabulary you wish to list the terms from
$items = array();
$terms = taxonomy_get_tree($vid);
foreach ( $terms as $term ) {  
    $count = db_result(db_query("SELECT COUNT(nid) FROM {term_node} WHERE tid = %d", $term->tid));  
    $items[] = l($term->name, "taxonomy/term/$term->tid") . " ($count)";
}
if ( count($items) ) {  print theme('item_list', $items);}

to generate a taxonomy list ... but i want to display ONLY CHILD ITEMS ... and the above mentioned code prints everything

NancyDru’s picture

foreach ($terms as $term) {
  if ($term->depth)
    $count = db_result(db_query("SELECT COUNT(nid) FROM {term_node} WHERE tid = %d", $term->tid)); 
    $items[] = l($term->name, "taxonomy/term/$term->tid") . " ($count)";
  }
}

BTW, you do realize that your count will include unpublished nodes as well as published?

jiakomo’s picture

I was suprised to find that I couldn't use views to display a sub-terms list. Maybe I was doing something wrong.
ajastraat, thanks for sharing this.

chriswb’s picture

Hey there. I'll try to give you a step-by-step guide for what you'd like to do.

Create a new view under administrator, site building, views.

In the basic information area, give it a name. You can also choose to limit the visibility to certain roles. Close the basic area.

Open the Page area. Select Provide page view. Edit the View Type to List. Make sure "use pager" is not checked. Enter the amount of items you want to list in the "nodes per page" area. If you don't want there to be a limit, put in 0. Close the page area.

Open the block area. Select Provide block. View Type, List. Give it a title and, once again, determine the number of items you want to list. Close the block area.

Open the filters area. Add a filter: Node: Published

Node Published equals: Yes

Add a second filter: Taxonomy terms for CATEGORY

Where "CATEGORY" is the category you would like to display.

Select the value you would like to be displayed.

Close the filter area.

Open the Sort Criteria area.

Add criteria "Node: Title" and choose ascending or descending.

Walla! You are done.

Rob_Feature’s picture

Hey Chris...
Unfortunately, this is what i've been trying to do for a long time. However, it creates multiple listings for the same taxonomy item...and adding "Node: distinct" doesn't cure that....

Don't suppose you know how to fix that?

-Bob Christenson
Owner/Designer, Mustardseed Media, Inc.
MustardseedMedia.com

/**
  * Bob Christenson
  * Mustardseed Media
  * http://mustardseedmedia.com
  */
chriswb’s picture

Bob,

Sorry, I have no idea why it'd do that. Strange!

mikemccaffrey’s picture

...that multiple listings of taxonomy terms are showing up is because the View is actually returning nodes and just showing the node's taxonomy. So if multiple nodes share the same taxonomy the terms will be duplicated.

Views only returns nodes, so you just want a list of category terms then you need to use a different solution, like some of the ones below.

- Mike McCaffrey

jasio’s picture

Hi,

I prefer another filter:

Taxonomy: Vocabulary Name
"Is all of"/"Is one of" (does not matter, if only one vocabulary is selected) 
Your vocabulary selected from list

For some reasons I feel more comfortable with it.

--
Best regards,

(js).

catch’s picture

I think this is included in the views bonus pack (untested)

Panels: By term, 3 columns
Requires panels.module -- terms presented as tables within columns such as http://sfbay.craigslist.org/.<

http://drupal.org/project/views_bonus

reggie75’s picture

Would the taxonomy_dhtml module be of any use?

http://drupal.org/project/taxonomy_dhtml

lukathonic’s picture

Hi,

I've done this with views - here is an export of my view:

$view = new stdClass();
$view->name = 'categories';
$view->description = 'Browse Subject Headings';
$view->access = array (
);
$view->view_args_php = '';
$view->page = TRUE;
$view->page_title = 'Browse Subject Headings';
$view->page_header = 'You are browsing a listing of the Land Centre\'s primary subject headings. For a complete listing of categories and subcategories, click here.


';
$view->page_header_format = '3';
$view->page_footer = '';
$view->page_footer_format = '1';
$view->page_empty = '';
$view->page_empty_format = '1';
$view->page_type = 'list';
$view->url = 'view/categories';
$view->use_pager = TRUE;
$view->nodes_per_page = '30';
$view->menu = TRUE;
$view->menu_title = 'Subject Headings';
$view->menu_tab = TRUE;
$view->menu_tab_default = TRUE;
$view->menu_tab_weight = '-10';
$view->sort = array (
array (
'tablename' => 'term_data',
'field' => 'weight',
'sortorder' => 'ASC',
'options' => '',
),
array (
'tablename' => 'node',
'field' => 'title',
'sortorder' => 'ASC',
'options' => '',
),
array (
'tablename' => 'node',
'field' => 'created',
'sortorder' => 'DESC',
'options' => 'normal',
),
);
$view->argument = array (
array (
'type' => 'taxletter',
'argdefault' => '6',
'title' => '%1',
'options' => '',
'wildcard' => '',
'wildcard_substitution' => '',
),
);
$view->field = array (
array (
'tablename' => 'node',
'field' => 'title',
'label' => '',
'handler' => 'views_handler_field_nodelink',
'sortable' => '1',
'options' => 'link',
),
);
$view->filter = array (
array (
'tablename' => 'node',
'field' => 'status',
'operator' => '=',
'options' => '',
'value' => '1',
),
array (
'tablename' => 'node',
'field' => 'type',
'operator' => 'OR',
'options' => '',
'value' => array (
0 => 'resources',
),
),
array (
'tablename' => 'node',
'field' => 'status',
'operator' => '=',
'options' => '',
'value' => '1',
),
array (
'tablename' => 'term_node_3',
'field' => 'tid',
'operator' => 'OR',
'options' => '',
'value' => array (
0 => '706',
1 => '1148',
2 => '471',
3 => '664',
4 => '1046',
5 => '796',
6 => '10',
7 => '1136',
8 => '13',
9 => '355',
10 => '1119',
11 => '9',
12 => '497',
13 => '70',
14 => '14',
15 => '822',
16 => '823',
17 => '821',
18 => '880',
19 => '11',
20 => '466',
21 => '49',
22 => '184',
23 => '51',
24 => '1211',
25 => '676',
26 => '819',
27 => '40',
28 => '626',
29 => '814',
30 => '700',
31 => '989',
32 => '243',
33 => '450',
34 => '303',
35 => '1210',
36 => '324',
37 => '1098',
38 => '648',
39 => '36',
40 => '170',
41 => '174',
42 => '1050',
43 => '173',
44 => '755',
45 => '1044',
46 => '521',
47 => '1195',
48 => '488',
49 => '313',
50 => '1169',
51 => '1107',
52 => '342',
53 => '181',
54 => '333',
55 => '299',
56 => '12',
57 => '8',
58 => '1133',
59 => '448',
60 => '805',
61 => '695',
62 => '506',
),
),
);
$view->exposed_filter = array (
);
$view->requires = array(term_data, node, term_node_3);
$views[$view->name] = $view;

Import this as a new view, then you'll need to change a few fields in the "filters" section to make it work, since your taxonomy terms are certainly different than these here.

This site is still under development, but if you want to see how this is working go to http://landcentre.dreamhosters.com/?q=view/categories

Cheers -

NancyDru’s picture

All that to do what jastraat did in just a few lines and no extra modules...

Nancy W.
now running 5 sites on Drupal so far
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in Your Database

Rob_Feature’s picture

Actually, Nancy...if this works, it would be MUCH easier for me to use than jastraat's PHP code..this is just an export of his View...and for us non-coders, it's much easier to update/tweak.

Another wonderful thing about views...import/export. I love this module! Thanks for utilizing this feature.

-Bob Christenson
Owner/Designer, Mustardseed Media, Inc.
MustardseedMedia.com

/**
  * Bob Christenson
  * Mustardseed Media
  * http://mustardseedmedia.com
  */
rdurrette’s picture

Whew...this node is a godsend...good thing I found it. I've been trying to create a professor rating system for a student-run website, and we've got each professor as a term within the category.

...kept running into your problem of having the duplicate terms.

I will try this and see if it works!

illSleepWheniDie’s picture

Using views would always be better than hacking away .... and definitely more accessible to non-developers ..

leoklein’s picture

Exactly, I'm doing a demo. If I told them to add code somewhere, they'd turn green.

I need something like what lukathonic has put together: list of taxonomy terms only using views.

NancyDru’s picture

Unless it's changed very recently, Views cannot display anything that is not attached to nodes. So something like a taxonomy or user list is not possible. Earl says he will do it some day, but probably not today.

Nancy W.
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in your database

leoklein’s picture

As I understand what's happening, this method -- "Taxonomy: Term Name/Summary, unsorted/: %1" -- shows terms that are currently being used (i.e. attached to a node). That's fine for me.

The people adding content and assigning terms will see the whole list in a Select List (i.e. the old fashion way) when they create a node.

pcs305’s picture

Following this discussion

Willdex’s picture

Looking at the site I suppose that it is possible to make a site's design look a bit like Craigslist? As least the classifieds section.
--
Billy | Major: Accounting | CityTech@CUNY | Student Block.

NancyDru’s picture

This was Michelle's "subscribe" comment. I'm no longer interested in this thread and tired of having to open it to get it out of my new items. I can't delete it since there's replies so I'm changing the name to nancyw since she's active in the thread.

femrich’s picture

I'm also posting to keep track of this thread.

Tom-182’s picture

I'm tracking this thread too, I'm still looking for a solution for this issue.

http://www.geektips.net

joshua_cohen’s picture

I am also looking for a good solution to this. I was using Taxonomy_DHTML, but it's very slow when there are thousands of terms involved. Bookmarking for now..

Josh

kuahyeow’s picture

So, the secret is choose an argument

"Taxonomy: Term Name" where the default is "Summary, sorted as view", and title is %1

Amazing!

--
Cheers,
Thong

Tip: http://drupal.org/forum-posting
Website: http://www.edoodle.co.nz

netentropy’s picture

what does the 1% do exactly?

joachim’s picture

The %1 puts the taxonomy term name into the title for the "subview" (the view once it's given an argument and is showing you nodes for a particular term, not sure if that's the right word for it).
In other words, when you click on a term in the main view, and see the nodes for that term, the title is also the term.
To get a different title, change the %1 to something else. Eg, on my site I'm putting "News from %1" because the terms are village names.

joachim’s picture

Excellent :)

Is there a way to get it to show terms for which no nodes exist yet?

NancyDru’s picture

joshua_cohen’s picture

I would love to hear how this is done. Did you have to hack Views to accomplish this? Please do share, I'm looking to do the same thing. I need a complete list of taxonomy, regardless of whether a node has been associated with that term yet.

Thank You,

Josh

NancyDru’s picture

eferraiuolo’s picture

Nice, this solved my issues, plus added a nice bit of information about how many nodes are tagged with each term! Great!

goldentoque’s picture

Was having a hard time getting a page with only on instance of each taxonomy term listed using views. This example worked like a charm and had the added bonus of displaying the number of nodes in that category, as well as having the second listing page of the individual node titles.

Nicely Done

Dustin Boston’s picture

Hey I'm not quite sure how to edit this script...here's what I did.

 $view = new stdClass();
$view->name = 'categories';
$view->description = 'Browse Subject Headings';
$view->access = array (
);
$view->view_args_php = '';
$view->page = TRUE;
$view->page_title = 'Browse Subject Headings';
$view->page_header = 'You are browsing a listing of the Land Centre\'s primary subject headings. For a complete listing of categories and subcategories, click here.

';
$view->page_header_format = '3';
$view->page_footer = '';
$view->page_footer_format = '1';
$view->page_empty = '';
$view->page_empty_format = '1';
$view->page_type = 'list';
$view->url = 'view/categories';
$view->use_pager = TRUE;
$view->nodes_per_page = '30';
$view->menu = TRUE;
$view->menu_title = 'Subject Headings';
$view->menu_tab = TRUE;
$view->menu_tab_default = TRUE;
$view->menu_tab_weight = '-10';
$view->sort = array (
array (
'tablename' => 'term_data',
'field' => 'weight',
'sortorder' => 'ASC',
'options' => '',
),
array (
'tablename' => 'node',
'field' => 'title',
'sortorder' => 'ASC',
'options' => '',
),
array (
'tablename' => 'node',
'field' => 'created',
'sortorder' => 'DESC',
'options' => 'normal',
),
);
$view->argument = array (
array (
'type' => 'taxletter',
'argdefault' => '6',
'title' => '%1',
'options' => '',
'wildcard' => '',
'wildcard_substitution' => '',
),
);
$view->field = array (
array (
'tablename' => 'node',
'field' => 'title',
'label' => '',
'handler' => 'views_handler_field_nodelink',
'sortable' => '1',
'options' => 'link',
),
);
$view->filter = array (
array (
'tablename' => 'node',
'field' => 'status',
'operator' => '=',
'options' => '',
'value' => '1',
),
array (
'tablename' => 'node',
'field' => 'type',
'operator' => 'OR',
'options' => '',
'value' => array (
0 => 'resources',
),
),
array (
'tablename' => 'node',
'field' => 'status',
'operator' => '=',
'options' => '',
'value' => '1',
),
);
$view->exposed_filter = array (
);
$view->requires = array(term_data, node);
$views[$view->name] = $view;
 

Basically I removed the references to term_node_3 because I was getting errors associated with that. It imported but my list looks like this:

# Interesting Links (1)
# Interesting Links (1)
# Interesting Links (1)
# Interesting Links (1)
# Interesting Links (1)
# Interesting Links (1)
# Interesting Links (1)
# Interesting Links (1)
# Interesting Links (1)
# Interesting Links (1)

Rather than

# Interesting Links (10)

Any ideas?

shrop’s picture

I was able to get this view to work by changing term_node_3 to term_node_2... in my case. The number represents the vid of the vocabulary you are trying to list. I also had to eliminate the filters and sorting stuff that was in there and then add back what I needed (ie: published = yes). Works well, but I think the php would work just as well and maybe easier since you can't just import this view and have it work out of the box.

It is good to know how to do this both way.

Thanks,
Shrop

Aren Cambre’s picture

I am getting the same problem with this view. Here's my view (still contains a lot of the text and settings from the original example):

  $view = new stdClass();
  $view->name = 'categories';
  $view->description = 'Browse Subject Headings';
  $view->access = array (
);
  $view->view_args_php = '';
  $view->page = TRUE;
  $view->page_title = 'Browse Subject Headings';
  $view->page_header = 'You are browsing a listing of the Land Centre\'s primary subject headings. For a complete listing of categories and subcategories, click here.

';
  $view->page_header_format = '3';
  $view->page_footer = '';
  $view->page_footer_format = '1';
  $view->page_empty = '';
  $view->page_empty_format = '1';
  $view->page_type = 'list';
  $view->url = 'view/categories';
  $view->use_pager = TRUE;
  $view->nodes_per_page = '30';
  $view->menu = TRUE;
  $view->menu_title = 'Subject Headings';
  $view->menu_tab = TRUE;
  $view->menu_tab_weight = '-10';
  $view->menu_tab_default = TRUE;
  $view->menu_tab_default_parent = NULL;
  $view->menu_parent_tab_weight = '0';
  $view->menu_parent_title = '';
  $view->sort = array (
    array (
      'tablename' => 'term_data',
      'field' => 'weight',
      'sortorder' => 'ASC',
      'options' => '',
    ),
    array (
      'tablename' => 'node',
      'field' => 'title',
      'sortorder' => 'ASC',
      'options' => '',
    ),
    array (
      'tablename' => 'node',
      'field' => 'created',
      'sortorder' => 'DESC',
      'options' => 'normal',
    ),
  );
  $view->argument = array (
    array (
      'type' => 'taxletter',
      'argdefault' => '6',
      'title' => '%1',
      'options' => '',
      'wildcard' => '',
      'wildcard_substitution' => '',
    ),
  );
  $view->field = array (
    array (
      'tablename' => 'node',
      'field' => 'title',
      'label' => '',
      'handler' => 'views_handler_field_nodelink',
      'sortable' => '1',
      'options' => 'link',
    ),
  );
  $view->filter = array (
    array (
      'tablename' => 'node',
      'field' => 'status',
      'operator' => '=',
      'options' => '',
      'value' => '1',
    ),
    array (
      'tablename' => 'node',
      'field' => 'type',
      'operator' => 'OR',
      'options' => '',
      'value' => array (
  0 => 'facts',
),
    ),
  );
  $view->exposed_filter = array (
  );
  $view->requires = array(term_data, node);
  $views[$view->name] = $view;

All it does is show my taxonomy terms that begin with A, and it repeats the taxonomy term for each time it is attached to a node. E.g.,:
- Aa (1)
- Aa (1)
- Aa (1)
- Aa (1)
- Aa (1)
- Aa (1)
- Aa (1)
- Aa (1)
- Aa (1)
- Aa (1)
- Aa (1)
- Ac (1)
- Ac (1)
- Ac (1)
- Ac (1)
- Af (1)
- Af (1)

Am I missing something?

I have a bad feeling that this isn't intended behavior for the view, so it could disappear in future Views module releases.

illSleepWheniDie’s picture

Try changing Arguments => default to "summary, unsorted" .. that did the trick for me .. I dunno how i figured that .. i was wondering how to fix it, and my hand just pulled down the selector and chose that option and *BAM* it worked ... paranormal drupal coding .. !creepy!.

iaminawe’s picture

Hi,

Really great thread... only thing is, when using "Summary, Unsorted" it seems to only spit out the taxonomy terms and not any other specified fields.

So for example I am using taxonomy images and I would like the relevant images to appear next to each taxonomy term listed with the number next to it.
I define Taxonomy image in the fields section but the view only outputs the text.

Anyone have any ideas?

It needs to be in a view and not a block as I am using Services to access the view info and feed it to flash.

Thanks in advance

SirMoby’s picture

That's a nice example for us poor hacks.

Thanks

NancyDru’s picture

rtandon’s picture

Hi Nancy, I have seen your appreciation for jastraat's code in this thread at multiple places. Indeed it's simple and elegant, I appreciate that too. I also happened to view your modified version of code, which I would have liked to include here for instant reference but would not do so 'coz you have the right to post that!

Now two points in this context
1) Your code follows more or less same logic, but jastraat's code includes another logic - which permits printing, only where there are non zero no. of terms in the vocabulary, which you have skipped. On similar lines you have also done the trick to include terms with non zero no of nodes. Would it not be best to combine both? I could have done that, but you might prefer to post it yourself.
2) While theses codes are elegant, perhaps quicker too - yet assuming views are cached, wont using the view be faster (just due to caching)

NancyDru’s picture

I left out terms with no nodes because I find that very confusing, especially in larger vocabularies. It is very simple to change.

Views, cached or not requires considerably more code (read: CPU) to do what this code can do easier. Further, Views requires several more queries in order to do it (caching will only mask that to some extent). Simple code is going to be more scalable than complex code.

<p>This is a sample of how to create a list of all terms that are being used from a particular vocabulary (category).</p>
<?php
  $vid = 2;         /* <---- put correct vocabulary ID here */
  $show_pic = module_exists('taxonomy_image');
  echo '<div class="use-pin">';
  $items = array();
  $terms = taxonomy_get_tree($vid);
  foreach ( $terms as $term ) {
      $count = taxonomy_term_count_nodes($term->tid);

      if ($count) {   /* don't show terms with 0 count */
        if ($show_pic) { $pic = taxonomy_image_display($term->tid, 'hspace="5"'); }
        else {$pic = NULL; }

        $name_and_count = l($pic . $term->name,'taxonomy/term/'.$term->tid, NULL, NULL, NULL, NULL, TRUE)." (".$count.") - ".$term->description;
        $items[] =  $name_and_count;
       }  /* end if count */
   } /* end foreach */

  if (count($items)) { print theme('item_list', $items); }
  else print 'No terms found';
  echo '</div>';
?>

This code now also includes support for the Taxonomy Image module.

Nancy W.
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in your database

newswatch’s picture

Thanks Nancy for this. A great help so far. But then this provides a block ACROSS all no types. I want to create a block which will only be for "story" nodes. Is there any way to do that?

Thanks.

I am using this code:

  $vid = 2; /* <---- put correct vocabulary ID here */
  $items = array();
  $terms = taxonomy_get_tree($vid);
  foreach ( $terms as $term ) {
    $count = taxonomy_term_count_nodes($term->tid);
    if ($count) { /* don't show terms with 0 count */
      $items[] = l($term->name,'taxonomy/term/'.$term->tid)." (".$count.") - ".$term->description;
    }
  } /* end foreach */
  print theme('item_list', $items);

-----------------------------
Subir Ghosh
www.subirghosh.in

NancyDru’s picture

Actually, this only counts the nodes for which the vocabulary is applicable. If the vocabulary is defined only for "story" type, then only "story" would be counted. However, if it's defined for "story" and "page" then it will count both.

I do have another method that separates the count by type on my site. http://nanwich.info/content_count_taxonomy_term

Nancy W.
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in your database

As If’s picture

This is a modified version of Nancy's code (see link above) to output an item list instead of a table:

<?php
  $vid = 1; /* <---- put correct vocabulary ID here */
  $typ = 'forum'; /* <---- put correct content type here */
  $vocab = taxonomy_get_vocabulary($vid);
  foreach ($vocab->nodes as $key => $value) {
    $type[] = $value;
  }
  $terms = taxonomy_get_tree($vid);
  foreach($terms as $term) {
    $count = 0;
    foreach($type as $content_type) {
      if($content_type == $typ) {
        $count = taxonomy_term_count_nodes($term->tid, $content_type);
      }
    }
    if ($count) {
      $items[] = l($term->name,'taxonomy/term/'.$term->tid)." (".$count.") - ".$term->description;
    }
  }
  echo theme('item_list', $items);
?>

-------------------------------------------
Interactive Worlds and Immersive Obsessions
http://www.asifproductions.com

-------------------------------------------
Interactive Worlds and Immersive Obsessions
http://www.asifproductions.com

NancyDru’s picture

It appears that you are only interested in a single content type here, so you can simplify the code.

The "foreach ($type..." [BTW, note the space in keeping with Drupal standards] isn't needed at all. The only part of that loop you need is $count = taxonomy_term_count_nodes($term->tid, typ); and note the change to the second parameter.

Also, if you have a rather large taxonomy, "taxonomy_term_count_nodes" is not the best performing function to use.

Nancy W.
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in your database

As If’s picture

I think you mean the if($content_type == $typ) statement isn't needed. (in other words, the $count = ... line does not need to be held within a conditional.) If so, you're right. I just tested it. But the foreach ($type... loop is actually needed.

"taxonomy_term_count_nodes" ;-) I just lifted that straight from your example!

-------------------------------------------
Interactive Worlds and Immersive Obsessions
http://www.asifproductions.com

-------------------------------------------
Interactive Worlds and Immersive Obsessions
http://www.asifproductions.com

NancyDru’s picture

Maybe I'm reading it wrong (which has been known to happen) but I think you only need "$count = taxonomy_term_count_nodes($term->tid, typ);"

"taxonomy_term_count_nodes" is something that everyone has. I was just warning you that there are more efficient versions of that available. For example, if you have my Site Documentation module, it uses a more streamlined version called "sitedoc_term_count_nodes" that can be called from external code. It just will be less resource-intensive.

Nancy W.
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in your database

Summit’s picture

Hi,
In almost all the posts I see the node count. Is it possible may be to show how to ouput the nodetitle and nodebody/teaser under the termnames instead of the count behind the termnames?
I would very much be helped with a efficient version of this code then!
Thanks in advance for your reply! ,
greetings,
Martijn

Summit’s picture

Yes! precisely like that, I like the different theming also :)
I like to use it with return theme('item_list', $links); [=> because other code where this peace should be implemented is made with this] Is this possible please?
See: http://drupal.org/node/128085#comment-717939 for the function I want to expand with this code.
Thanks a lot in advance!

Greetings,
Martijn

NancyDru’s picture

<?php
  $vid = 1;         // <---- put correct vocabulary ID here
  $terms = taxonomy_get_tree($vid);
  $items = array();

  foreach ($terms as $term) {
    $count = taxonomy_term_count_nodes($term->tid);

    // Note: the number of nodes selected per term is controlled by 'feed_default_items' from the RSS publishing settings page.

    $result = taxonomy_select_nodes(array($term->tid), 'or', 0, FALSE, 'n.sticky DESC, n.created DESC');
    $children = array();
    while ($node = db_fetch_object($result)) {
      $children[] = node_view(node_load($node->nid), TRUE, FALSE, FALSE);
    }
    $items[] = array(
      'data' => l($term->name,'taxonomy/term/'.$term->tid)." (".$count.") - ".$term->description,
      'children' => $children,
      );
   }
   echo theme('item_list', $items);
?>

Nancy W.
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in your database

Summit’s picture

Hi Nancy,

This is what I made of it, and it is working with Panels_taxonomy!

function panels_taxonomy_child_terms_list($tid, $vid, $args, $argidx){
  $count ='';
  foreach (taxonomy_get_children($tid, $vid) as $child_tid => $child_term) {
    $args[$argidx] = $child_tid;
    $items = array();
    $result = taxonomy_select_nodes(array($child_term->tid), 'or', 0, FALSE, 'n.sticky DESC, n.created DESC');
    $children = array();
    $count = taxonomy_term_count_nodes($child_term->tid);    
    while ($node = db_fetch_object($result)) {
       $children[] = node_view(node_load($node->nid), TRUE, FALSE, FALSE);
    }
    $items[] = array(
      'data' => l($child_term->name,'taxonomy/term/'.$child_term->tid)." (".$count.") - ".$child_term->description,
      'children' => $children,
      );
    }
  return theme('item_list', $items);
}

Thanks a lot for your help with this! It is working.
EDIT: May be very strange question.
But should I use:

taxonomy_render_nodes(taxonomy_select_nodes(array($child_term->tid), 'or', 0, FALSE, 'n.sticky DESC, n.created DESC');
);

Instead of taxonomy_select_nodes?

Greetings,
Martijn

NancyDru’s picture

You could, but you lose the theme_item_list that you said you wanted. Then you would also need to change the "children" building.

Nancy W.
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in your database

NancyDru’s picture

You could, but you lose the theme_item_list that you said you wanted. Then you would also need to change the "children" building.

Nancy W.
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in your database

Summit’s picture

Hi Nancy, I leave it than. I don't know how to change this, and what the benefits and disadvantages are. It is working now, so I leave it this way, right?
Greetings, Martijn

Summit’s picture

Hi Nancy, Do you know how I can get rid of the bullets? They look ugly on my site?
Thanks in advance for your reply!

Greetings, Martijn

NancyDru’s picture

Put something like this in your CSS:

.no-bullets {
  list-style-type: none;
}

And then make sure the <ul> gets a class="no-bullets".

Nancy W.
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in your database

Summit’s picture

Hi Nancy,

This is my code. It works fine, but shows the bullet and I would like only to show the nodes of the story content-type. Could you please look into this. What do I need to change in the code, so the no-bullet class will work, and what to get only the story nodes in the list?

function panels_taxonomy_child_terms_list($tid, $vid, $args, $argidx){
  $items = array();

  foreach (taxonomy_get_children($tid, $vid) as $child_tid => $child_term) {
    $args[$argidx] = $child_tid;
    $count = taxonomy_term_count_nodes($child_term->tid);
    // Note: the number of nodes selected per term is controlled by 'feed_default_items' from the RSS publishing settings page.

    $result = taxonomy_select_nodes(array($child_term->tid), 'or', 0, FALSE, 'n.sticky DESC, n.created DESC');
    $children = array();
    while ($node = db_fetch_object($result)) {
      $children[] = node_view(node_load($node->nid), TRUE, FALSE, FALSE);
    }
    $items[] = array(
      'data' => l($child_term->name,'taxonomy/term/'.$child_term->tid)." (".$count.") - ".$child_term->description,
      'children' => $children,
      );
    }
    return theme('item_list', $items);
  }

Thanks a lot in advance!

greetings,
Martijn

NancyDru’s picture

Change return theme('item_list', $items);
to return theme('item_list', $items, null, 'ul', array('class' => 'no-bullets'));

Summit’s picture

Hi Nancy,

It is not working on Internet Explorer.
I added this to my style.ccs in my garland theme:

ul.no-bullets {
  list-style-type: none;
  background-image: none;
}

But firefox only shows the item-list css and gives no-bullet as class inside item-list.
The backgrond image gives the bullets in garland, but on IE 6 the bullets are still there..
Please assist.

thanks in advance!
greetings,
Martijn

NancyDru’s picture

Remember that if you change the Garland style sheet, you need to force it to recreate the active styles by (for example) changing the color scheme.

Nancy W.
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in your database

Summit’s picture

Hi Nancy,
This is what I see in the code:
<div class="content"><div class="item-list"><ul class="no-bullets">
But the no-bullets class is not overruling the item-list class. Shouldn't it be a div class?
Do you also know how to select only the 'story' contenttype in above code?
Thanks for the tip!
greetings,
Martijn

NancyDru’s picture

ul.no_bullets li {
list-style-type: none;
background-image: none;
}

As If’s picture

how narrow can these comments get?

-------------------------------------------
Interactive Worlds and Immersive Obsessions
http://www.asifproductions.com

NancyDru’s picture

As If’s picture

I can't stop!

-------------------------------------------
Interactive Worlds and Immersive Obsessions
http://www.asifproductions.com

NancyDru’s picture

As If’s picture

OUCH!

-------------------------------------------
Interactive Worlds and Immersive Obsessions
http://www.asifproductions.com

jyg’s picture

Shedding the pounds!

NancyDru’s picture

Wish I could get this thin!

jyg’s picture

Jack Sprat could eat no fat!

pharma’s picture

i think so

gausarts’s picture

A very long thread ever and narrowest comment : D

love, light n laughter

salientknight’s picture

I was able to put this together based on your Code Nancy. I'm sure its not the Drupal way 100% but I thought it might help out some others... if for no other use than picking at the parts. The part people probably wont like, is that I cobbled all this together in a block using the php filtered text.
Thanks for the post that go me started :)

  • grabs all terms from specified vids
  • limits search to published nodes
  • wraps results in divs with dynamic ids
  • presents list in drill down menu format -- click the title to see the list

THE CODE

//basic javascript show hide using CSS display property
<script>
function showOrHide(x){
	var box=document.getElementById(x);
	 if (!box.style.display || box.style.display == "none") { 
        box.style.display = "block";
    }
    else {
        box.style.display = "none";
    }

}
</script>
<?php
$vids=array(9,2,12,8,1,11,10); //the vocabs you want to list
$vidsName=array('Title1','Title2','Title3','Title4','Title5','Title6','Title7'); //the titles of those vocabs
$c=0;
foreach ( $vids as $i ) {  
          $vid = $i;  // Set the vid to the vocabulary id of the vocabulary you wish to list the terms from
          $items = array();
          $terms = taxonomy_get_tree($vid);
          foreach ( $terms as $term ) {  
$sqlStr ="SELECT COUNT(node.nid) FROM node node  INNER JOIN term_node term_node ON node.vid = term_node.vid  LEFT JOIN node_revisions node_revisions ON node.vid = node_revisions.vid WHERE (node.status = 1) AND (term_node.tid =".$term->tid.")";
   

 $count = db_result(db_query($sqlStr));  
              $items[] = l($term->name, "taxonomy-searh/term/$term->tid") . " ($count)"; // you views search page
}
if ( count($items) ) {  
    print "<a href=# id='toggle".$i."' onClick=\"showOrHide('theme".$i."');\">+ ".$vidsName[$c++]."</a><br />";
    print "<div id='theme".$i."' class='themes toggleState'>"; 
    print theme('item_list', $items);
    print "</div>";
}

}

The View page

$view = new view;
$view->name = 'taxonomy_search';
$view->description = '';
$view->tag = '';
$view->base_table = 'node';
$view->human_name = 'Taxonomy Search';
$view->core = 6;
$view->api_version = '3.0-alpha1';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Defaults */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->display->display_options['use_ajax'] = TRUE;
$handler->display->display_options['access']['type'] = 'none';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['style_plugin'] = 'list';
$handler->display->display_options['style_options']['row_class'] = 'search-list';
$handler->display->display_options['row_plugin'] = 'fields';
/* Field: Node: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['label'] = '';
$handler->display->display_options['fields']['title']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['title']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['title']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['title']['alter']['external'] = 0;
$handler->display->display_options['fields']['title']['alter']['replace_spaces'] = 0;
$handler->display->display_options['fields']['title']['alter']['trim_whitespace'] = 0;
$handler->display->display_options['fields']['title']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['title']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['title']['alter']['trim'] = 0;
$handler->display->display_options['fields']['title']['alter']['html'] = 0;
$handler->display->display_options['fields']['title']['element_label_colon'] = 1;
$handler->display->display_options['fields']['title']['element_default_classes'] = 1;
$handler->display->display_options['fields']['title']['hide_empty'] = 0;
$handler->display->display_options['fields']['title']['empty_zero'] = 0;
$handler->display->display_options['fields']['title']['link_to_node'] = 1;
/* Field: Node: Body */
$handler->display->display_options['fields']['body']['id'] = 'body';
$handler->display->display_options['fields']['body']['table'] = 'node_revisions';
$handler->display->display_options['fields']['body']['field'] = 'body';
$handler->display->display_options['fields']['body']['label'] = '';
$handler->display->display_options['fields']['body']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['body']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['body']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['body']['alter']['external'] = 0;
$handler->display->display_options['fields']['body']['alter']['replace_spaces'] = 0;
$handler->display->display_options['fields']['body']['alter']['trim_whitespace'] = 0;
$handler->display->display_options['fields']['body']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['body']['alter']['max_length'] = '255';
$handler->display->display_options['fields']['body']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['body']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['body']['alter']['strip_tags'] = 1;
$handler->display->display_options['fields']['body']['alter']['trim'] = 1;
$handler->display->display_options['fields']['body']['alter']['html'] = 0;
$handler->display->display_options['fields']['body']['element_label_colon'] = 1;
$handler->display->display_options['fields']['body']['element_default_classes'] = 1;
$handler->display->display_options['fields']['body']['hide_empty'] = 1;
$handler->display->display_options['fields']['body']['empty_zero'] = 0;
/* Argument: Taxonomy: Term ID */
$handler->display->display_options['arguments']['tid']['id'] = 'tid';
$handler->display->display_options['arguments']['tid']['table'] = 'term_node';
$handler->display->display_options['arguments']['tid']['field'] = 'tid';
$handler->display->display_options['arguments']['tid']['style_plugin'] = 'default_summary';
$handler->display->display_options['arguments']['tid']['default_argument_type'] = 'taxonomy_tid';
$handler->display->display_options['arguments']['tid']['default_argument_options']['term_page'] = 1;
$handler->display->display_options['arguments']['tid']['default_argument_options']['node'] = 0;
$handler->display->display_options['arguments']['tid']['default_argument_options']['limit'] = 0;
$handler->display->display_options['arguments']['tid']['default_argument_skip_url'] = 0;
$handler->display->display_options['arguments']['tid']['break_phrase'] = 0;
$handler->display->display_options['arguments']['tid']['add_table'] = 0;
$handler->display->display_options['arguments']['tid']['require_value'] = 0;
$handler->display->display_options['arguments']['tid']['reduce_duplicates'] = 0;
$handler->display->display_options['arguments']['tid']['set_breadcrumb'] = 0;
$handler->display->display_options['arguments']['tid']['use_synonym_for_summary_links'] = 0;
/* Filter: Node: Published */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'node';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = '1';

/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page_1');
$handler->display->display_options['path'] = 'taxonomy-searh/term/%';
$translatables['taxonomy_search'] = array(
  t('Defaults'),
  t('more'),
  t('Apply'),
  t('Reset'),
  t('Sort by'),
  t('Asc'),
  t('Desc'),
  t('Items per page'),
  t('- All -'),
  t('Offset'),
  t('All'),
  t('Page'),
);
pr0test0r’s picture

In D6.x, Nancy's code will throw this annoying error caused by changes in the l() function.

Fatal error: Unsupported operand types in ......common.inc on line 1445

The problem is the list of arguments after the href argument (those NULLs and true). They now have to be in an array. For more on this stuff, check out the explanation at the bottom of this blog entry.

But in most cases, dropping those arguments altogether should probably work:

$name_and_count = l($pic . $term->name,'taxonomy/term/'.$term->tid)." (".$count.") - ".$term->description;
joyltd’s picture

Firstly, thank you so much for your contributions to Drupal. I've used many of your taxonomy modules/code snippets in the past and for that I'm really grateful. thanks also to the many other contributions here.

I've found this sample code of yours (from years ago!) and have tweaked it to display the title first, image beneath and lastly term description at the bottom in a neat little box.

Personally, I can read but not write php, so i can usually find my way to a solution...but I've got a really stupid question!

How would i go about displaying this list without using theme item_list? Once it prints the theme item_list, the div classes I have added are preceded by class="item-list". I don't want to change the general item_list css as i use this elsewhere on the website. Basically I want to display the list horizontally, so outputting the list without theme item_list would allow me to use my own classes and display my neat little boxes for terms and term images.

I use a similar method with Taxonomy Context that doesn't use the item_list and I've spent a long time trying to merge them with no success (I know its probably obvious to you or any other php coders out there!).

Any suggestions are much appreciated. Thanks in advance.

Summit’s picture

Hi, showing what code you have now, would help a lot.
Greetings, Martijn

joyltd’s picture

Hi Martijn,
Thanks for the quick reply...much appreciated. I've been away for a few days otherwise I'd have got straight back to you.
Here's my code:

	  $vid = 36;         /* <---- put correct vocabulary ID here */
	  $show_pic = module_exists('taxonomy_image');
		  
	  echo '<div class="vocabulary-container">';
	  $items = array();
	  $terms = taxonomy_get_tree($vid);
	  foreach ( $terms as $term ) {
		  $count = taxonomy_term_count_nodes($term->tid);
	
		  if ($count) {   /* don't show terms with 0 count */
			
			if ($show_pic) { $pic = l(taxonomy_image_display($term->tid), taxonomy_term_path($term), null, null, null, null, true);$img = l(taxonomy_image_display($term->tid), taxonomy_term_path($term), null, null, null, null, true); }
			//if ($show_pic) { $pic = taxonomy_image_display($term->tid, 'hspace="5"'); }
			else {$pic = NULL; }
		
			 $name_and_count = '<div class="out-about-container"><div class="out-about-subterm"><h2 class=title">'. l($term->name,'taxonomy/term/'.$term->tid) .'</h2><div class="out-about-image">'. $pic .'</div><div class="out-about-taxodesc">'. $term->description .'</div></div></div>';
			 				
			$items[] =  $name_and_count;
		   }  /* end if count */
	   } /* end foreach */
	
	  if (count($items)) { print theme('item_list', $items); }
	  else print 'No terms found';
	  echo '</div>';
	

Thanks in advance for your time.

florianr’s picture

Hello and Thanks for that thread, dealing with my Problem!

1. I tried to import that view, changed the settings for the taxonomy terms but I only get a blank page ... Any hints?

2. Does that only work if I know all taxonomy terms? Sinze I use freetagging it would be nice to have a solution working, without knowing all terms. (could I set a wildcard for the term?

3. the php snipet, shown abouve, could that be changed to sort the output? I want the last added term to be the first in the list.

4. I would prefer not only to have the list of terms, linking to the summary page, I want to have a list showing the term and bello it all assigned nodes with title and teaser. Any ideas?

adshill’s picture

Ok so... I've managed to get the block that displays the terms I need, plus I've managed to get it to display on all nodes of the content type to which the vocabulary is associated using some php code from the drupal site, the question is, how do I get the block to be displayed on each taxonomy term list pages for that vocabulary. Otherwise navigation is floored by the fact the user has to click back to get to a different term list.

Any ideas?!

The section/site is this: http://www.thegraffitiproject.net/links

Thanks for any help that can be given!

justin_d’s picture

Hi, Adam

I think these module does what u need exactly.

Refine by Taxonomy.
http://drupal.org/project/refine_by_taxo

Justin
-- eliminate web developers and designers !!
-Dries Buytaert, Drupalcon 2007 yahoo summit.

MrPrise’s picture

I use the argument: taxonomy: term name / summary,sorted ascending too, but I have a problem with it.
If the term is only one word I dont have my nice views but I have the basic node teaser list. The terms with more than one words displayed with my custom views. I use pathauto to have nice urls. I have no idea why doesnot work with one word lenght terms...

dabro’s picture

Bookmarking, I want to try this.

droople’s picture

Will need this one day

Suzy’s picture

..

dindon’s picture

you can use views_fusion?

diegohermes’s picture

Very useful.

jjjames’s picture

I gotta try this

NancyDru’s picture

Take a look at Taxonomy List

A slightly different way can be achieved with the Site documentation module doing http://www.examplesite.com/sitedoc/vocabulary/xxx - it will include a count by content types.

Nancy W.
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in your database

wonder95’s picture

Nancy, the Taxonomy List module is perfect for listing categories. I'm creating a photo gallery site using Angie Byron's article at lullabot.com, and so I already have a view created that lists photos for a given term with an argument of the term name. Since the path I'm using was photos/tags, all I had to do was modify _taxonomy_list_get_table() to use my path and to use the term name, and it works like a charm.

Quick question; is it possible to override that function in a separate module instead of having to hack yours? From what I understand, the function name is prefixed with an underscore because it is just an internal function available to the module, which means the answer to my question would be no. Correct?

NancyDru’s picture

I wish I could take credit for Taxonomy List, but it is not my module. Typically, functions that start with an underscore are not documented interfaces and may change without warning. However, I can point to quite a few places in Drupal where such functions are used by other modules.

You might create a feature request for that module to allow for what you want. Given the widespread use of Views, they might do it for you.

Nancy W.
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in your database

mkmckinn’s picture

All,
If you're looking to create a photo gallery that lets folks view photos tagged with specific features (e.g. location (here, there), time (day, night), subject (person, building)). I created this view to let the audience choose photos based on taxonomy terms (admittedly a fixed set of terms). Using the prior example terms, the view can show all day photos, or all day photos of a building, taken here.
The view below is what I came up with:

$view = new stdClass();
$view->name = 'PhotoGallery';
$view->description = 'Photo Gallery';
$view->access = array (
0 => '15',
1 => '14',
2 => '16',
3 => '13',
4 => '12',
5 => '7',
6 => '8',
7 => '9',
8 => '10',
9 => '3',
10 => '5',
11 => '4',
12 => '6',
13 => '11',
);
$view->view_args_php = '';
$view->page = TRUE;
$view->page_title = '';
$view->page_header = '';
$view->page_header_format = '1';
$view->page_footer = '';
$view->page_footer_format = '1';
$view->page_empty = '';
$view->page_empty_format = '1';
$view->page_type = 'bonus_grid';
$view->url = 'photogallery';
$view->use_pager = FALSE;
$view->nodes_per_page = '0';
$view->sort = array (
array (
'tablename' => 'node',
'field' => 'title',
'sortorder' => 'ASC',
'options' => '',
),
);
$view->argument = array (
);
$view->field = array (
array (
'tablename' => 'image',
'field' => 'nid',
'label' => '',
'handler' => 'image_views_handler_image_img_link',
'options' => 'thumbnail',
),
array (
'tablename' => 'term_node_1',
'field' => 'name',
'label' => '',
'options' => 'link',
),
array (
'tablename' => 'term_node_5',
'field' => 'name',
'label' => '',
'options' => 'link',
),
);
$view->filter = array (
array (
'tablename' => 'node',
'field' => 'status',
'operator' => '=',
'options' => '',
'value' => '1',
),
array (
'tablename' => 'node',
'field' => 'type',
'operator' => 'OR',
'options' => '',
'value' => array (
0 => 'image',
),
),
array (
'tablename' => 'term_node_2',
'field' => 'tid',
'operator' => 'OR',
'options' => '0',
'value' => array (
0 => '15',
1 => '49',
2 => '25',
3 => '13',
4 => '14',
),
),
array (
'tablename' => 'term_node_1',
'field' => 'tid',
'operator' => 'OR',
'options' => '2',
'value' => array (
0 => '1',
1 => '2',
2 => '3',
3 => '50',
4 => '61',
5 => '62',
6 => '63',
7 => '64',
8 => '65',
9 => '66',
10 => '67',
11 => '68',
12 => '69',
13 => '70',
14 => '71',
15 => '72',
16 => '4',
17 => '5',
18 => '73',
19 => '74',
20 => '75',
21 => '76',
22 => '77',
23 => '78',
24 => '79',
25 => '80',
26 => '81',
27 => '82',
28 => '83',
29 => '84',
30 => '85',
31 => '86',
32 => '87',
33 => '88',
34 => '89',
35 => '90',
36 => '91',
37 => '92',
38 => '93',
39 => '94',
40 => '95',
41 => '96',
42 => '97',
43 => '98',
44 => '225',
45 => '226',
46 => '227',
47 => '228',
48 => '229',
49 => '230',
50 => '231',
51 => '232',
52 => '6',
53 => '7',
54 => '8',
55 => '233',
56 => '234',
57 => '235',
58 => '236',
59 => '237',
60 => '238',
61 => '239',
62 => '240',
63 => '241',
64 => '99',
65 => '118',
66 => '119',
67 => '120',
68 => '121',
69 => '122',
70 => '123',
71 => '100',
72 => '124',
73 => '125',
74 => '126',
75 => '127',
76 => '128',
77 => '129',
78 => '130',
79 => '131',
80 => '132',
81 => '133',
82 => '101',
83 => '138',
84 => '139',
85 => '140',
86 => '141',
87 => '102',
88 => '142',
89 => '143',
90 => '144',
91 => '103',
92 => '145',
93 => '146',
94 => '147',
95 => '148',
96 => '149',
97 => '150',
98 => '151',
99 => '152',
100 => '153',
101 => '154',
102 => '104',
103 => '155',
104 => '156',
105 => '157',
106 => '158',
107 => '105',
108 => '159',
109 => '160',
110 => '161',
111 => '162',
112 => '163',
113 => '164',
114 => '165',
115 => '166',
116 => '167',
117 => '168',
118 => '169',
119 => '170',
120 => '106',
121 => '171',
122 => '172',
123 => '173',
124 => '174',
125 => '175',
126 => '107',
127 => '176',
128 => '177',
129 => '178',
130 => '179',
131 => '180',
132 => '181',
133 => '182',
134 => '183',
135 => '184',
136 => '185',
137 => '186',
138 => '187',
139 => '188',
140 => '189',
141 => '190',
142 => '191',
143 => '108',
144 => '192',
145 => '109',
146 => '193',
147 => '194',
148 => '195',
149 => '196',
150 => '197',
151 => '198',
152 => '110',
153 => '199',
154 => '200',
155 => '201',
156 => '111',
157 => '202',
158 => '203',
159 => '204',
160 => '112',
161 => '205',
162 => '206',
163 => '207',
164 => '208',
165 => '209',
166 => '210',
167 => '211',
168 => '212',
169 => '213',
170 => '214',
171 => '113',
172 => '215',
173 => '216',
174 => '217',
175 => '218',
176 => '114',
177 => '220',
178 => '115',
179 => '222',
180 => '116',
181 => '223',
182 => '117',
183 => '224',
184 => '9',
185 => '10',
186 => '11',
187 => '12',
),
),
array (
'tablename' => 'term_node_5',
'field' => 'tid',
'operator' => 'OR',
'options' => '1',
'value' => array (
0 => '58',
1 => '244',
2 => '243',
3 => '247',
4 => '245',
5 => '246',
6 => '59',
7 => '60',
),
),
);
$view->exposed_filter = array (
array (
'tablename' => 'term_node_1',
'field' => 'tid',
'label' => 'Store',
'optional' => '1',
'is_default' => '0',
'operator' => '1',
'single' => '1',
),
array (
'tablename' => 'term_node_2',
'field' => 'tid',
'label' => 'Program',
'optional' => '1',
'is_default' => '0',
'operator' => '1',
'single' => '1',
),
array (
'tablename' => 'term_node_5',
'field' => 'tid',
'label' => 'Project',
'optional' => '1',
'is_default' => '0',
'operator' => '1',
'single' => '1',
),
);
$view->requires = array(node, image, term_node_1, term_node_5, term_node_2);
$views[$view->name] = $view;

anschinsan’s picture

Thanks for the exported views! I was rather despaired ...

Now that I've found this post, I can go to bed :)

Have a good night!
anschinsan

colan’s picture

-

nishitdas’s picture

Is there any way can differentiate the root taxonomy from the child taxonomy in the list using the Views
Example:

Taxonomy Root1:

Taxonomy Child A under Root1
Taxonomy Child B under Root1
Taxonomy Child C under Root1

Taxonomy Root2:

Taxonomy Child A under Root2
Taxonomy Child B under Root2
Taxonomy Child C under Root2

aswalla’s picture

Subscribing as well...

Erdbert’s picture

very helpful

OwnSourcing’s picture

-

Pol’s picture

Drupal is a mature tool, views seems to be too...

I'm still amazed that we cannot have list of Taxonomy terms in a bloc... why is it so complex ?

Anyway... subscribing too

-Pol-

Pol’s picture

Here is the code that you need to do what you want...

It list distinct categories and link to content who belong to that category ;) (taxonomy term)

Thanks for Drupal and that marvellous views module !

Import that views:

$view = new stdClass();
$view-&gt;name = 'CategoryBloc';
$view-&gt;description = '';
$view-&gt;access = array (
0 =&gt; '1',
1 =&gt; '2',
);
$view-&gt;view_args_php = '';
$view-&gt;page = FALSE;
$view-&gt;page_title = '';
$view-&gt;page_header = '';
$view-&gt;page_header_format = '3';
$view-&gt;page_footer = '';
$view-&gt;page_footer_format = '3';
$view-&gt;page_empty = '';
$view-&gt;page_empty_format = '3';
$view-&gt;page_type = 'list';
$view-&gt;url = 'taxonomy/term';
$view-&gt;use_pager = TRUE;
$view-&gt;nodes_per_page = '10';
$view-&gt;block = TRUE;
$view-&gt;block_title = 'Categories';
$view-&gt;block_header = '';
$view-&gt;block_header_format = '3';
$view-&gt;block_footer = '';
$view-&gt;block_footer_format = '3';
$view-&gt;block_empty = '';
$view-&gt;block_empty_format = '3';
$view-&gt;block_type = 'list';
$view-&gt;nodes_per_block = '10';
$view-&gt;block_more = TRUE;
$view-&gt;block_use_page_header = FALSE;
$view-&gt;block_use_page_footer = FALSE;
$view-&gt;block_use_page_empty = FALSE;
$view-&gt;sort = array (
array (
'tablename' =&gt; 'term_data',
'field' =&gt; 'weight',
'sortorder' =&gt; 'ASC',
'options' =&gt; '',
),
);
$view-&gt;argument = array (
array (
'type' =&gt; 'taxid',
'argdefault' =&gt; '3',
'title' =&gt; '',
'options' =&gt; '3',
'wildcard' =&gt; '',
'wildcard_substitution' =&gt; '',
),
);
$view-&gt;field = array (
array (
'tablename' =&gt; 'term_data',
'field' =&gt; 'name',
'label' =&gt; '',
'handler' =&gt; 'views_handler_field_tid_link',
'defaultsort' =&gt; 'ASC',
),
array (
'tablename' =&gt; 'term_node_3',
'field' =&gt; 'name',
'label' =&gt; '',
'options' =&gt; 'link',
),
);
$view-&gt;filter = array (
);
$view-&gt;exposed_filter = array (
);
$view-&gt;requires = array(term_data, term_node_3);
$views[$view-&gt;name] = $view;

-Pol-

newswatch’s picture

I get an error "Unable to get a view out of that." in trying to import that view

-----------------------------
Subir Ghosh
www.subirghosh.in

trevorleenc’s picture

replace &gt; with >
melian’s picture

Bookmarking too, will try this...

Ciprian M.
Webdesign & Multimedia

funkyfrieder’s picture

Did one of you also solve the problem, that the menu doesn't collaps when using taxonomy menu links or views that list taxonomy teasers?

femrich’s picture

I've created a related discussion on this issue here:

http://drupal.org/node/186471 : Views: How a (somewhat post-) newb thinks through the taxonomy view problem....

dcoder’s picture

I'm trying to use views for something related, but I need to list the terms of other vocabulary inside the nodes. I mean:

I have the vocabulary "Sections" [ Politics, Entertainment, Society, etc ]
I have a free-tagging vocabulary named "Tags" -every node has one "Section" and several "Tags"-

I need to list the most popular "Tags" in the Section "Politics" -and for every other Section-
I think I most get all the nodes in "Politics", take all the Tags in every node and list by popularity..

How can I do this?

Any help will be *greatly appreciated*

femrich’s picture

I'd suggest starting a new thread for this one. Otherwise it will be buried at the bottom of a looooonnnngg discussion...

harrypark’s picture

Yeah this discussion has gotten pretty long

Quint’s picture

yeah, the thread that goes on and on and on.

Is there a way to unsubscribe from a thread?

dejbar’s picture

I would also greatly appreciate help. The summary view in arguments doesn't seem to allow this. If you select a term from one vocabulary then you can't get a summary of terms for another vocabulary.

I was kind of hoping this would work

/myview/[term1]/[vocab2]/[term2]

so the url /myview/[term1]/[vocab2] would display this but instead it displays an empty list.

NancyDru’s picture

Kalian’s picture

How to change this code:

<?php

$vid = 1;  // Set the vid to the vocabulary id of the vocabulary you wish to list the terms from
$items = array();
$terms = taxonomy_get_tree($vid);
foreach ( $terms as $term ) {  
    $count = db_result(db_query("SELECT COUNT(nid) FROM {term_node} WHERE tid = %d", $term->tid));  
    $items[] = l($term->name, "taxonomy/term/$term->tid") . " ($count)";
}
if ( count($items) ) {  print theme('item_list', $items);}
?>

to generate Taxonomy list in 2 columns?

NancyDru’s picture

While I do multiple terms in columns (using tables) in some of my modules, I've never tried this. It might be an interesting exercise.

If you want a list to come out like this:

* a      * b
* c      * d
* e      * f

I would think this could be done totally with CSS, although you'd probably want to use a wrapper ("<div>") to make sure you didn't change all item lists throughout the site. The key would be to use "position: relative."

If you want the list to come out like this:

* a      * d
* b      * e
* c      * f

This may be a bit more difficult. Perhaps the array_slice function might be useful.

Nancy W.
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in your database

ep-1’s picture

Check out A List Apart: Multicolumned Lists for help with the css for two column lists.

EP

Sree’s picture

that a useful link ....

-- Sree --
IRC Nick: sreeveturi

NancyDru’s picture

dreadfulcode’s picture

It's an old link, but still relevant and very helpful.. Thanks again.

Kalian’s picture

ep, thanks for link, it's very interesting.
nancyw, yes, that's what I need. But I don't find how it was done on your site.

NancyDru’s picture

mzafer’s picture

Hi Nancy,

If I want to create a page for a Vocabulary that lists the terms and few articles from each term how can it be done. Saw you link, that lists the terms and a description of the term, but I want to list few articles for each term.

Thanks
Zafer

NancyDru’s picture

Now you're getting into Views territory. I don't know for sure if it can do this.

I'll take a look and see if I can cobble something together. Do you just want titles or also teasers? In what order?

I'm beginning to wonder if I should gather all these little snippets together to put into a module.

Nancy W.
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in your database

mzafer’s picture

I'll take a look at the views, whether it can do this. I want the teasers also to showup.

> I'm beginning to wonder if I should gather all these little snippets together to put into a module.

That would really be great.

Thanks
Zafer

NancyDru’s picture

<?php
  $vid = 1;         // <---- put correct vocabulary ID here
  $terms = taxonomy_get_tree($vid);
  echo '<ul>';

  foreach ($terms as $term) {
    $count = taxonomy_term_count_nodes($term->tid);
    echo "\n<li>". l($term->name,'taxonomy/term/'.$term->tid)." (".$count.") - ".$term->description .'</li>';

    // Note: the number of nodes selected is controlled by 'feed_default_items' from the RSS publishing settings page.

    $result = taxonomy_select_nodes(array($term->tid), 'or', 0, FALSE, 'n.sticky DESC, n.created DESC');
    echo "\n<ul>";
    while ($node = db_fetch_object($result)) {
      echo "\n<li>". node_view(node_load($node->nid), TRUE, FALSE, FALSE) .'</li>';
    }
    echo '</ul>';
   }
  echo '<ul>';
?>

Nancy W.
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in your database

mzafer’s picture

Thanks Nancy.. that worked

Zafer

salvatoreco’s picture

Hi Nancy, good snippet, thanks. But I want to display just last node for each term without changeing the 'feed_default_items': I'm creating an image gallery with imagecache, imagefield and views, so I use a vocabulary for image sets and i'd like to display term list with imagefield thumbs from last node for each term, is this possible? I've tried with Views modules, but i can't do that!

Thanks and sorry for my bad English :-D

Kalian’s picture

Some categories have subcategories. Function taxonomy_get_tree generate Taxonomy List with all categories and all subcategories. What to do to generate Taxonomy List only with categories?
And how to do to print count of all nodes from all subcategories of one category?

NancyDru’s picture

If I remember (without re-looking at the code), there is an option "depth" parameter; set it to 0 (or 1?).

Nancy W.
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in your database

Kalian’s picture

nancyw, thanks for vocabulary_term_count_columns.
With "depth = 0" there are no subcategories in Taxonomy List.

NancyDru’s picture

Kalian’s picture

But I used taxonomy_get_tree($vid, $parent = 0, $depth = 0, $max_depth = NULL).
But your line is shorter, so I'll use your variant.

DesignWork’s picture

Hi Nancy,

the code should be like this: taxonomy_get_tree($tid, -1, 1), I have testet it in 5.x.

Dirk

dhovey’s picture

I have been trying to get the depth option on my Taxonomy filter to work and it seems like all I should have to put in the box is 1 or depth=1. Neither has worked. Is there something that I am missing? I didn't see anything in Taxonomy help for this.

The taxonomy is called functional areas and it has two levels. I have an exposed filter that I only want the first level to display as an option for people to select.

Please help before I look like Bill Murray in King Pin!

CharlieR’s picture

I would like it to show the terms only from specific subcategory:

Example:

I've got in my taxonomy:
Country
- City1
-- Suburb1
-- Suburb2
-- Suburb3
-- Suburb4
- City2
- City3
- City4
.
.
.
And I would like it to show the suburbs of City1 in the block.
I was trying to do something by changing the numbers in taxonomy_get_tree($tid, 0, -1, 1) and by modifying the code but couldn’t get it to work. (don't know much php)

Kalian’s picture

Try to use not taxonomy_get_tree($tid, 0, -1, 1), but taxonomy_get_tree($vid, 1, -1, 1)
If it will be City2, so taxonomy_get_tree($vid, 2, -1, 1).

CharlieR’s picture

Thanks for the quick reply Kalian

But it seems to be like if I put anything else than 0 in the parent ($parent = 0), the block wont show anything.

I see the logic that placing 1 in the parent would mean that "City" is the parent but somehow it shows only blank. -1 doesn't work either.

I keep testing and I let you know if I get it to work, which is unlike because I've got no idea what I’m doing.

CharlieR’s picture

So the term ID for my city wasn't "1", it was "36". Now its working like it should.

vanessa_83’s picture

Hi to all!

I'm working with Drupal for roughly one week, and the last few days I'm trying to set up a "News" page. I have created a category called "News" with two taxonomy terms: "General news" and "Mysite News". Moreover I added a new content type called "news".

To cut a long story short, i created a page and a block with the views module for "News" and in general it works ok. The page and the block are displayed as a Teaser List with a 'more' link.

All of the above (and a lot more) were created thanks to this forum advices and instructions. The problem is that i can't find an answer to the following issues though i spend a lot of time searching and reading. Anyway here it is:

  1. The url of the news page is mysite/news but once i hit the 'more' link of the page/block the url displayed is mysite/?q=node/2.
    Same problem when i hit the "General News" link where the url is mysite/?q=taxonomy/term/2. Is there a way to display the url according to the category? p.ex. mysite/news/?q=generalnews for the taxonomy term and mysite/news/?q=generalnews/id=123 for the 'more' link.
  2. Is there a way to resize the title displayed in the block for each post?.I searched the .css files but i can't find the class that refers to the title according to the page source.Any ideas?
  3. Last i would like to ask if there is a way not to display the authoring information at the "News" page.

Any help for any of these???(Note that i'm not very familiar to php coding)
Thanks in advance!
V.

funkyfrieder’s picture

Hi

1)I have the same problem with the URL but I don't have a solution.
2)It is somewhere in the style.css (I found it once)
3)You should be able to hide the authoring information by unchecking this option under administration->sitebuilding->themes->Global settings->display post information on

homeshop’s picture

Hello
With the help of drupal I am building a business directory.

I have a big problem with views. I have a vocabulary named Domain Names and a company node. when someone ads their company they have to choose a domain name. How can I make a view to show a list of all the domain names and when I click the domain it shows all the companies in there. I hope you understand.
Thank you

DesignWork’s picture

Hi Nancy,

I found this post while I was trying to put a pager in the image_gallery module. The Problem is, that the image gallery makes a taxonomy list wich is endless. So I want to give it an admin from to choose how many galleries are shown in a list. But I´m not able to make the code working! But somehow it´s not working on the gallery_list.

Maybe you find my error....

/**
 * Image gallery callback, displays an image gallery
 */
function image_gallery_page($type = NULL, $tid = 0) {
$galleries = taxonomy_get_tree(_image_gallery_get_vid(), $tid, -1, 1);
    for ($i=0; $i < count($galleries); $i++) {
    $galleries[$i]->count = taxonomy_term_count_nodes($galleries[$i]->tid, 'image');
    $tree = taxonomy_get_tree(_image_gallery_get_vid(), $galleries[$i]->tid, -1);
    $descendant_tids = array_merge(array($galleries[$i]->tid), array_map('_taxonomy_get_tid_from_term', $tree));
    // The values of $descendant_tids should be safe for raw inclusion in the
    // SQL since they're all loaded from integer fields in the database.
    
	$sql = 'SELECT n.nid FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE tn.tid IN ('. implode(',', $descendant_tids) .') AND n.status = 1 ORDER BY n.sticky ASC, n.created ASC';
	
	// +++++ pager query ++++ new code
	$sqlresult = pager_query($sql, variable_get('galleries_per_page', 10), 0);
	
	if ($nid = db_result(db_query_range(db_rewrite_sql($sql), 0, 1))){
		// show me a pager ++++ new code
		while ($node = db_fetch_object($sqlresult)) {
      $galleries[$i]->latest = node_load(array('nid' => $nid));
    }
	} /* end while */
  } 

  $images = array();
  if ($tid) {
    $result = pager_query(db_rewrite_sql("SELECT n.nid FROM {term_node} t INNER JOIN {node} n ON t.nid=n.nid WHERE n.status=1 AND n.type='image' AND t.tid=%d ORDER BY n.sticky ASC, n.created ASC"), variable_get('image_images_per_page', 6), 0, NULL, $tid);
    while ($node = db_fetch_object($result)) {
      $images[] = node_load(array('nid' => $node->nid));
    }

    $gallery = taxonomy_get_term($tid);
	
    $parents = taxonomy_get_parents($tid);
    foreach ($parents as $parent) {
      $breadcrumb[] = array('path' => 'image/tid/'. $parent->tid, 'title' => $parent->name);
    }
    $breadcrumb[] = array('path' => 'image', 'title' => t('Image galleries'));
    $breadcrumb = array_reverse($breadcrumb);
    drupal_set_title($gallery->name);
  }

  $breadcrumb[] = array('path' => $_GET['q']);
  menu_set_location($breadcrumb);
  $content = theme('image_gallery', $galleries, $images);
  // old Code $content = theme('image_gallery', $galleries, $images) . '<div class="description">' . check_markup($gallery->description) . '</div>';
  return $content;
}

This shows me an pager but only on the frist level. But this pager does not work on the taxonomy(gallery)_list

Please some Help

Dirk

Borromini’s picture

Thanks jastraat for the PHP code :). This stuff is all pretty new to me (especially PHP and stuff), but it works flawlessly! And Drupal, well, it just rocks :P.

STyL3’s picture

+1

Devis’s picture

- Subscribing -

Same issue and more complexity using multilingual vocabularies/nodes (i18n).

--
Italy

msameer’s picture

Awesome! Subscribing.

timb’s picture

- bottmanbros.com

- bbros.us -
Who else is interested in Lunch?

funkeyrandy’s picture

$taxo_id = 	$filter;
$list_no =5;
$qfuery = "SELECT node.title, node.nid FROM node INNER JOIN term_node ON node.nid = term_node.nid WHERE type='content-ah_video_entry' AND(term_node.tid = $taxo_id) AND status=1 ORDER BY RAND() LIMIT 0,10";
   	$fresult = db_query($qfuery);
   	while($qffile = db_fetch_object($fresult)) {                                         // Walk through all the files
   		$qffiles[] = $qffile;
	

   	}     

   	if($qffiles) {
   		
   		foreach($qffiles as $qffile) {  
			
			
			

$terms = taxonomy_node_get_terms_by_vocabularyd($qffile->nid,7);






  foreach($terms as $term){
 //$output .= l($term->name, "node/5369/$term->tid", array('rel' => 'tag', 'title' => strip_tags($term->description))).',';

$theone .= '<a href="/node/5369/'.$term->tid.'">'.$term->name."</a>,";




  }		
			
	  }			
	
			
      	}

$string_array=array_unique(explode(",",$theone));
$ioutput[]=$string_array[0];
for($i=1;$i<count($string_array);$i++){
if(!in_array($string_array[$i],$ioutput)){
echo $string_array[$i];
}
}

?>
trevorleenc’s picture

just starting a project which I think this discussion will prove rather useful..

I'm sure I'll have a question or two in the near future or so regarding a local/regional classifieds site I'm in the process of designing/building.

awesome thread!

aozuas’s picture

Summit’s picture

Hi,
This thread is very interesting. Thanks for all the input. I have may be a very simple question.
How to use http://drupal.org/node/128085#comment-636635 to show in a block the child terms of the term which is shown through the url and show underneath the node-title and node-teaser?

child term 1
--Node title 1
--Node teaser 1
--Node title 2
--Node title 2

child term 2
etc..

I think I have to alter this http://drupal.org/node/128085#comment-636635 a little to get this done. Can anyone help with this?

My starting code is the following (from panels_taxonomy, to get the child code):

function panels_taxonomy_child_terms_list($tid, $vid, $args, $argidx)
{  $links = array(); 
    foreach (taxonomy_get_children($tid, $vid) as $child_tid => $child_term) 
   { $args[$argidx] = $child_tid; $links[] = l($child_term->name, implode('/', $args)); 
    } 
    return theme('item_list', $links); 
} 

This shows in panels_taxonomy my child terms, but not the underneath nodes..and the module is not planned to do so in the near future as I read the documentation.

Thanks a lot in advance! Nancy do you know how to proceed?
greetings,
Martijn

mzafer’s picture

Hi Martijn,

I think the below is the code ur are looking for. It has my css stuff too, you can strip it or modify it. Also it does not display the teaser but just titles. But getting it should be easy, I think $node->teaser should work. You can try it out.

<?php
  $vid = 2;         // <---- put correct vocabulary ID here
  $terms = taxonomy_get_tree($vid);  // < -- Get the terms for the vocab

  foreach ($terms as $term) {
    $count = taxonomy_term_count_nodes($term->tid); //<-- node count for a term
    if ($count > 0 )
    {
    	echo "\n<div class='cat-section'>";
       	echo "\n<div class='cat-section-header'>". l($term->name,'taxonomy/term/'.$term->tid).$term->description .'</div>';
       	// Note: the number of nodes selected is controlled by 'feed_default_items' from the RSS publishing settings page.
       	$result = taxonomy_select_nodes(array($term->tid), 'or', 0, FALSE, 'n.sticky DESC, n.created DESC'); //<-- Get the nodes in a term
       	while ($node = db_fetch_object($result)) { //<-- retrieve the node
       		echo "\n<div class='cat-section-list'>". l($node->title,'node/'.$node->nid).'</div>'; //<-- show title as node link
       	}
       	echo "\n</div>";
    }
   }
?>

-ZM

giggler’s picture

I got this from drupalsnippet.com and it will list the term with sub terms, how do you make it so that the sub terms only show when you click on the main terms?

<?php
// accordion taxonomy menu
// by Chris Herberte
// ** don't forget to change $vocabulary
//
$vocabulary = 1;
//drupal_add_js('misc/collapse.js');
$lastdepth = 1;
$topoflist = 1;
$nid = 0;
if (arg(0) == 'node' && is_numeric(arg(1)) && ! arg(2)) {
    $nid = arg(1);
    $terms = taxonomy_node_get_terms($nid);
    rsort($terms);
    $tid = $terms[0]->tid;
} elseif (arg(0) == 'taxonomy' && arg(1) == 'term') {
    $terms = preg_split('/[+ ,]/', arg(2));
    $tid = $terms[0];
}
$parents = taxonomy_get_parents($tid);
foreach ($parents as $parent) {
    $i++;
}
$tree = taxonomy_get_tree($vocabulary);

foreach ($tree as $key => $term) {
    if ( $term->depth == 0 ) {
        $title = $term->name;
        if ($topoflist == 0) {
            print '</ul></li></ul>'."\n";
        }
        if ($tree[$key+1]->depth==1){
            if ($term->tid == $parent->tid) {
                print '<ul>'."\n".
                '<li class="title active" onClick="showHide(event)">'.$title.
                "\n".'<ul class="active">'."\n";
            } else {
                print '<ul>'."\n".
                 '<li class="title">'.l($title,'taxonomy/term/'.$term->tid).
                "\n".'<ul class="menu">'."\n";
            }
        }
        else {
            print '<ul>'."\n".
                '<li class="title">'.l($title,'taxonomy/term/'.$term->tid).
                "\n".'<ul class="menu">'."\n";
        }
        $topoflist = 0;
    }
    if ($term->depth > 0) {
        if ($term->tid == $tid) {
            print '<li id="darker">' . l($term->name, "taxonomy/term/$term->tid") . '</li>' . "\n";
        } else {
            print '<li class="leaf notdarker">' . l($term->name, "taxonomy/term/$term->tid") . '</li>' . "\n";
        }
    }
    $lastdepth = $term->depth;
}
print '</ul></li></ul>';
?>
trevorleenc’s picture

This is cool, thanks...definatly a step in the right direction for me.

Now, and maybe I'm already going in the wrong direction, but I started my process with using taxonomy_dss, which is pretty cool, so maybe that might help you here...

you can see an example of what I am working on here:

http://dev.sellingconnection.com/node/49

Choose NC Greensboro, and it will take you to a sub-terms page...

My Question though, is how to make the above snipplet not display Terms which currently do not have any sub-terms or nodes...

trevorleenc’s picture

I think anyway, tried like hell to find your link: drupalsnippet.com, it should be: drupalsnippets.com

:)

giggler’s picture

oops, I was too busy thinking about the code. Should have just copied over the url. I forgot to mention that I wanted the sub sections as drilldown style, now leaving the parent terms.

Yours is getting somewhere. How was it set up? The only thing is that it doesn't give the nice title-in-url and is using the number. This can be done with Taxonomy menu (I think that was the module along with dhtml menu). It gives a nice dthml drilldown to sub sections. I just don't like the fact that it has /category/1/1 as url. I would prefer /category/1/title-name for seo reasons. I do like the drilldown method though since it's more user friendly than having to go back to a page to look at previous terms.

http://www.drupalsnippets.com/snippet/category/menus
I think you'll just need to try out each of them and see which might work better. I wish I knew how to combine them, but I can't code really.

trevorleenc’s picture

no worries on the url :)

the title in url is something that will come when I install pathauto...usually one of the last things I install on a site, as I want to have all my meat and potatoes ready before I start pouring gravy on them :)

I don't recall having even looked at taxonomy menu, though I probably did (I've goofed around with just about every taxonomy module there is so far), but I'm using taxonomy DSS (http://drupal.org/project/taxonomy_dss)

this is a desired effect, as I will want someone to be able to click on a node's tags, and be taken to a listing of terms as opposed to a view of nodes. Still not sure if this is the best way just yet to have site visitors navigate, but it's what I've come up with so far.

So in a node, if you click on Electronics, you'll be taken to a list taxonomy list of Locations which are also tagged with Electronics, and vice-versa.

-t

giggler’s picture

I've just installed taxonomy DSS and...is there suppose to be a menu for it under Site Configuration? I don't see any config page or anything referring to DSS...

Do you have basic step by step as to how to do this? I'm so lost...

trevorleenc’s picture

It works out of the box, no config necessary...

what it does, after installed, is when you click on a taxonomy term...say "NC Greensboro", creates a "view" of sorts, that shows all taxonomy terms which are assigned to nodes with the term "NC Greensboro", thereby creating a give me where this, and this...

So, clicking NC Greensboro (term/25), and then clicking on Electronics (term/59), will give you a view based on term/25,59, in other words, show me all nodes that have "NC Greensboro" and "Electronics"...

Right now my demo site is in a bit of a shambles, so I can't go and rebuild this from scratch at the moment to see what did and didn't work at the time :)

trevorleenc’s picture

taxonomy redirect only handles TERM, and not TERMID

I'm running into this with another site of mine too...where I'd like to redirect TERMID somewhere other than a default taxonomy_term view

*ugh* this is fun ain't it :)

NancyDru’s picture

trevorleenc’s picture

and when you're right, you're right :)

I do have views installed, sorry I did leave that part out, but generally such an integral part of my "base" install for Drupal, I kind of forgot...

giggler’s picture

I've changed the menu to use this and with trevorlee_nc's method of using Taxonomy DSS, I was able to use the following for a right sidebar menu, and the DSS creates the sub term menu in the page content area. Now if I can just theme it so that the sub term menu will be to the left of the content instead of above the content, then I think it will work pretty good as a directory:

$vid = 1;
$terms = taxonomy_get_tree($vid);
print '<div id="menu"><ul>';
foreach ($terms as $term) {
$tcount = taxonomy_term_count_nodes($term->tid);
if ($term->depth == 0) {
print "<li>".l($term->name." (".$tcount.")",'taxonomy/term/'.$term->tid, array('title' => $term->name))."</li>";
}
}
print '</ul></div>';

NancyDru’s picture

Right now, this build the entire taxonomy tree and then only looks at the top level. This is potentially wasteful of resources.

$terms = taxonomy_get_tree($vid, 0, -1, 0); would limit the tree to only the top level and save those CPU resources for something useful.

Nancy W.
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in your database

giggler’s picture

Thanks Nancy...

Do you know how to create a list of only subterms and shown only when you are on any of the subterms for the particular main term?

NancyDru’s picture

Not off the top of my head, but I wouldn't think it would be that hard to figure out. Why not look through the taxonomy module? BTW, if you do, "subterms" are called "children." I would probably start with taxonomy_get_children, which is specifically designed to get the children of any term.

Nancy W.
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in your database

giggler’s picture

ok, I found this code which does the job, but the pain is having to create each main term as a block to show in that term. If you have a few main terms only, then it's not too bad.

NancyDru’s picture

giggler’s picture

This code, but I do need to create a block for each term. If there are subterms (children) for those, then I don't know what would happen.

<?php
$tid = 4;
$items = array();
$children = taxonomy_get_children($tid);
foreach ( $children as $child ) {
$count = db_result(db_query("SELECT COUNT(nid) FROM {term_node} WHERE tid = %d", $child->tid));
$items[] = l($child->name, 'taxonomy/term/'. $child->tid). ' ('.$count.') ';
}

print theme('item_list', $items);
?>
giggler’s picture

This code, but I do need to create a block for each term. If there are subterms (children) for those, then I don't know what would happen.

<?php
$tid = 4;
$items = array();
$children = taxonomy_get_children($tid);
foreach ( $children as $child ) {
$count = db_result(db_query("SELECT COUNT(nid) FROM {term_node} WHERE tid = %d", $child->tid));
$items[] = l($child->name, 'taxonomy/term/'. $child->tid). ' ('.$count.') ';
}

print theme('item_list', $items);
?>

refine by taxonomy didn't seem to work...

ranavaibhav’s picture

This is what i was looking for..thank you very very much

Jackie R

sockah’s picture

I read through all this and it was very helpful but I couldn't find an answer to this specific question. How can you make a collapsible directory (in a view or block) based on a particular vocab . In other words, how can you spit out:
Category1
Category2
Category3

Then, when you click on Category 1, it turns into:

Category1
--Sub-category1
--Sub-category2
Category2
Category3

(I tried the directory module, btw, and for various reasons, it didn't do what I needed).

awasson’s picture

I'm not sure if you're still looking but I saw a good resource referred to earlier in this thread that describes exactly what you're looking for: http://www.drupalsnippets.com/snippet/category/menus

(This was originally posted by giggler I think)

kirikintha’s picture

NOTE: I am using the "category" module that came with drupal - not using any other stuff except for the Tagadellic module.

Here's my exported view - hopefully this should work for anyone - but I do have the views extras added in, just an FYI
This produces a list of all taxo terms in my "taxonomy" vocabulary, in a list view.
Just change the option to your needs (I had to exclude a few terms, remember too many terms and the view gives a join error, mysql can only join so many things together)
Hopefully this helps someone!

$view = new stdClass();
$view->name = 'all_taxonomy_terms';
$view->description = 'These are all the tags in the taxonomy vocabulary';
$view->access = array (
);
$view->view_args_php = '';
$view->page = TRUE;
$view->page_title = 'All Tags (Taxonomy Vocabulary)';
$view->page_header = '';
$view->page_header_format = '7';
$view->page_footer = '';
$view->page_footer_format = '7';
$view->page_empty = '';
$view->page_empty_format = '7';
$view->page_type = 'list';
$view->url = 'view/all_taxonomy';
$view->use_pager = FALSE;
$view->nodes_per_page = '0';
$view->sort = array (
);
$view->argument = array (
array (
'type' => 'taxletter',
'argdefault' => '4',
'title' => '%1',
'options' => '0',
'wildcard' => '',
'wildcard_substitution' => '',
),
);
$view->field = array (
array (
'tablename' => 'term_node_3',
'field' => 'name',
'label' => '',
'options' => 'link',
),
);
$view->filter = array (
array (
'tablename' => 'node',
'field' => 'status',
'operator' => '=',
'options' => '',
'value' => '1',
),
array (
'tablename' => 'term_node',
'field' => 'tid',
'operator' => 'NOR',
'options' => '',
'value' => array (
0 => '18',
),
),
array (
'tablename' => 'term_data',
'field' => 'vid',
'operator' => 'AND',
'options' => '',
'value' => array (
0 => '3',
),
),
);
$view->exposed_filter = array (
);
$view->requires = array(term_node_3, node, term_node, term_data);
$views[$view->name] = $view;

Nothing unreal exists.

NancyDru’s picture

There is no "category" module that comes with Drupal. It was an unfortunate decision (which is now corrected) to refer to the Taxonomy module with the menu title "Categories." There is a contributed module called "Categories," but it is NOT the same.

kirikintha’s picture

Sorry, I am using the base install of Drupal - I had 5.1 for so long I forgot. I am just using the core taxonomy module and tagadellic. My bad!

Nothing unreal exists.

yeeloon’s picture

Hi all!

I need some help here. How can I possible generate and display something like this:

Taxonomy 1
- Node Title 1
- Node Title 2
- Node Title 3

Taxonomy 2
- Node Title 4
- Node Title 5
- Node Title 6

and so forth... to print all the terms in that particular Vocabulary.

It is something similar to shopping directory / sitemap. In a way, I want to print all the Taxonomies together with its node Title in one full page. I've went thru a few examples at (http://drupal.org/node/47412), such as http://drupal.org/node/74715 , this only divides the taxonomy according to alphabets and does not list everything.

I hope someone can tell me how to achieve the above.

Thanks in advance!
yeeloon

NancyDru’s picture

yeeloon’s picture

Hi Nancy,

Thanks for the help. I think I have got it from http://drupal.org/node/128085#comment-723936.

Cheers!
yeeloon

jfall’s picture

I packaged together a little script that will produce this type of nodes-by-term summary for a Views view. It uses the view to format the nodes under each term, and can optionally put each top-level term into a fieldset to tidy-up the display.

But you must define a view first to filter the nodes and define their layout and then override the summary view in template.php to call this little function.
This works great in conjunction with the Taxonomy Redirect module.

See http://drupal.org/node/225426#comment-770201

daytripscanada’s picture

Ok.. similar to everyone else.. but yet different.

I have a large taxonomy setup like:

Site
-Cat1
oCat2
*Cat3
*Cat4
*Cat5
oCat6
oCat7
-Cat8

etc.

I want to be able to display a list of all nodes (titles only) that exist under each 2nd level category (and all of it's sub categories - 3rd level, 4th level).

So I want to be able to create a link at the bottom of say "Cat2" to say "show all articles in this category" which then creates a list like:

-Cat2
oCat3
*Node1 Title
*Node2 Title
*Node3 Title
oCat4
*Node1 Title
*Node2 Title
*Node3 Title
oCat5
*Node1 Title
*Node2 Title
*Node3 Title

And each title links to the full story.

Basically I want to create an index of all the content under the top level categories without forcing the user to drill down into the sub categories.

NancyDru’s picture

Take a look at Taxonomy Browser and/or Taxonomy List and see if something would be easy to modify.

NancyDru (formerly Nancy W. until I got married to Drupal)

awasson’s picture

This is a wonderfully informative thread! I am particularly thankful of jastraat's block and Nancy's tips. That block does exactly what I wanted it to!

If you're not big on views or php blocks, have a look at the Vocabulary Index module (http://drupal.org/project/vocabindex) I don't think I'll use it in production but it makes an easy index page for Category terms. Some more info on using it as a directory index page (feature request) here: http://drupal.org/node/225916

Thanks,
Andrew

pharma’s picture

excellent thread!

doomed’s picture

How do we make this code work with translated taxonomy terms ?

I'm using i18n to change between English and other languages, but the output is always coming in English.

NancyDru’s picture

In general all you need to do is to add a "db_rewrite_sql". If you point to which code, I'll do the change.

Nancy W.
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in your database

doomed’s picture


<?php
  $vid = 1;         // <---- put correct vocabulary ID here
  $terms = taxonomy_get_tree($vid);
  $items = array();

  foreach ($terms as $term) {
    $count = taxonomy_term_count_nodes($term->tid);

    // Note: the number of nodes selected per term is controlled by 'feed_default_items' from the RSS publishing settings page.

    $result = taxonomy_select_nodes(array($term->tid), 'or', 0, FALSE, 'n.sticky DESC, n.created DESC');
    $children = array();
    while ($node = db_fetch_object($result)) {
      $children[] = node_view(node_load($node->nid), TRUE, FALSE, FALSE);
    }
    $items[] = array(
      'data' => l($term->name,'taxonomy/term/'.$term->tid)." (".$count.") - ".$term->description,
      );
   }
   echo theme('item_list', $items);
?>

NancyDru’s picture

Interesting. Taxonomy_get_tree uses "db_rewrite_sql" so I would have thought it should be pulling in the terms with the currently set locale. I'm not sure what to do next. Perhaps a support request for the i18n module, including this snippet. If you do, please use my contact form to send me a link to it; I'd like to know.

Nancy W.
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in your database

ar-jan’s picture

Subscribing - especially interested in future solutions for the issue with i18n.

NancyDru’s picture

Drupal 6 has many improvements for internationalization. There will be no core improvements in 5.x, and probably none in 6.x unless they are shown to be serious bugs. Drupal 7 is open for code changes, so if you have suggestions in that area, you need to file an issue against core (http://drupal.org/project/issues/drupal).

Nancy W.
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in your database

doomed’s picture

Summit’s picture

Children Taxonomy list filtered by story?

Hi Nancy and others!,
I am not getting the Children taxonomy list correctly filtered by nodetype "story".
Can you please assist?

The code I now have is:

function panels_taxonomy_child_terms_list($tid, $vid, $args, $argidx){
   $stories = node_get_types('type', array('type' => 'story'));
   foreach ($stories as $node) {
   
   $items = array();

   foreach (taxonomy_get_children($tid, $vid) as $child_tid => $child_term) {
    $args[$argidx] = $child_tid;

    $count = taxonomy_term_count_nodes($child_term->tid);
    // Note: the number of nodes selected per term is controlled by 'feed_default_items' from the RSS publishing settings page.

    $result = taxonomy_select_nodes(array($child_term->tid), 'or', 0, FALSE, 'n.sticky DESC, n.created DESC');
    
    $children = array();
    while ($node = db_fetch_object($result)) {
      $children[] = node_view(node_load($node->nid), TRUE, FALSE, FALSE);
    }
    $items[] = array(
      'data' => l($child_term->name,'taxonomy/term/'.$child_term->tid)." (".$count.") - ".$child_term->description,
      'children' => $children,
      );
    }
    }
    return theme('item_list', $items, null, 'ul', array('class' => 'no-bullets'));
  } 

But it is not working..:(
Thanks a lot for your answer in advance!
greetings,
Martijn

NancyDru’s picture

I think you've made this more complex than it needs to be, but can you explain your goal?

Nancy W.
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in your database

Summit’s picture

Hi,

Nancy helpt me to get this working.
Change:

    while ($node = db_fetch_object($result)) {
      $children[] = node_view(node_load($node->nid), TRUE, FALSE, FALSE);

to:

while ($node = db_fetch_object($result)) {
      $content = node_load($node->nid);
      if ($content->type == 'story') {
        $children[] = node_view($content, TRUE, FALSE, FALSE);
      }
    }

Greetings, Martijn

TheresaM’s picture

very interesting thread

nicolaisen_nancy’s picture

Hi Nancy-
I've been following your comments all over the place in my efforts to learn Drupal, and have come up against a problem I can't solve--probably because I am looking at this the wrong way. So here goes:
--I have two vocabularies, authors and topics.
--Each applies to both story and blog content.
--I want a block entitled "Stories By Topic'' which shows *only* the stories for a particular voc term
--I'll repeat this strategy for remaining voc/content type combinations.

Using something a lot like the jstraat code, I can get a voc block which returns content by topic ( term ), but it returns *both*types of content, not just one

If I use separate vocabularies for each content type, I can't figure out how to show the corrrect voc blocks for the content type and hide the other set.

Hope you and the other thread contributers can shed a little light. Thank you ever so much for your great thread, NN

NancyDru’s picture

Summit's problem was pretty much the same. After you load the node, you need to check its content type.

Nancy W.
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in your database

fletchgqc’s picture

subscribing

SocialNicheGuru’s picture

subscribing

http://SocialNicheGuru.com
Delivering inSITE(TM), we empower you to deliver the right product and the right message to the right NICHE at the right time across all product, marketing, and sales channels.

fallsemo’s picture

subscribing.

salviadepot’s picture

thanks again nancy for this tips

subscribing for sure!

www.salviadepot.com

Summit’s picture

Hi Nancy,

I would like to have a block with the sister terms of the taxonomy/term page which I see in term view mode.
What I would like is to have a block next to this with the sister terms, the node-titles and teasers underneath.

For example I have a trekking in Annapurna region in Nepal, the block needs to show first the (sister terms) other regions in nepal, the nodes titles and teasers underneath and not also the annapurna region nodes.

Thanks a lot for going into this in advance!

greetings,
Martijn

NancyDru’s picture

Well, you can start by getting the parent term (taxonomy_get_parent) then get the children of that term (probably depth=1) and unset the current term. Using that list, you can use taxonomy_select_nodes and taxonomy_render_nodes.

NancyDru (formerly Nancy W. until I got married to Drupal)

Summit’s picture

Hi Nancy,

I think I need something like:

<?php
// split out taxonomy terms by parent
function bowwowtheme_liquid_print_terms($nid) {
  $terms = taxonomy_node_get_terms($nid);
  $links = array();
  $processed = array();
  if($terms){
    foreach($terms as $term){
      $parents = taxonomy_get_parents_all($term->tid);
      foreach($parents as $parent){
        if(!in_array($parent->tid, $processed)){
          $links[] = l($parent->name, taxonomy_term_path($parent), array('rel' => 'tag', 'title' => strip_tags($parent->description)));
          $processed[] = $parent->tid;
        }
      }
    }
    $output = theme('item_list', $links);
    return $output;
  }
}
?>

but than with parent - sister looking. Do you know the alteration of the code for that please?
Thanks a lot in advance!

greetings,
Martijn

Summit’s picture

Anyone has Parent looking code, instead of children please?
Thanks in advance for sharing?

greetings,
Martijn

Leeteq’s picture

FYI - there is also this module: http://drupal.org/project/tinytax

"Displays a vocabulary as a tree within a block. Provides blocks for each of the vocabularies on a site. Browsing the terms within a block is done via AJAX like calls, making it quick and a light load on the server."

.
--
( Evaluating the long-term route for Drupal 7.x via BackdropCMS at https://www.CMX.zone )

viewtest15’s picture

I think the below is the code you are looking for. It has css stuff too, you can strip it or modify it. Also it does not display the teaser but just titles. But $node->teaser should work. You can try it out.

Also, if you want to edit php code out of drupal, you can add block and than just require_once "/folder_in_site_root/php_file_with_code".

  $vid = 2;         // <---- put correct vocabulary ID here
  $terms = taxonomy_get_tree($vid);  // < -- Get the terms for the vocab

  foreach ($terms as $term) {
    $count = taxonomy_term_count_nodes($term->tid); //<-- node count for a term
    if ($count > 0 )
    {
        echo "\n<div class='cat-section'>";
           echo "\n<div class='cat-section-header'>". l($term->name,'taxonomy/term/'.$term->tid).$term->description .'</div>';
           // Note: the number of nodes selected is controlled by 'feed_default_items' from the RSS publishing settings page.
           $result = taxonomy_select_nodes(array($term->tid), 'or', 0, FALSE, 'n.sticky DESC, n.created DESC'); //<-- Get the nodes in a term
           while ($node = db_fetch_object($result)) { //<-- retrieve the node
               echo "\n<div class='cat-section-list'>". l($node->title,'node/'.$node->nid).'</div>'; //<-- show title as node link
           }
           echo "\n</div>";
    }
   }

---
>Play Online

Taxoman’s picture

Hi all, this is a related issue, hope it fits into this amazing, knowledge-building thread...

Are there anyone here who knows how to filter and sort on 2 taxonomy vocabularies?
From: http://drupal.org/node/302162

"Desired result:
A view that shows all posts assigned to a person, sorted alphabetically on the priority names.

The vocabulary in a) holds priority levels.
The vocabulary in b) holds names of people who some content is assigned to.

a) Initial filter: List teasers from posts that have terms anywhere in a hierarchy under a specific term (term/NN/all)
b) limit the list in a) to a specific term in a second vocabulary (a vocabulary that holds names of people, limit to list posts tagged (assigned to) only one person)
c) sort the resulting list not on latest date, but alphabetically on the terms in the vocabulary in a) "

lesliewu’s picture

Is it possible to show a list view of the terms instead of a list of teasers when a term is selected?

NancyDru’s picture

lesliewu’s picture

Thanks for the quick reply. What I want to achieve is, whenever I click on a term, all the nodes associated with that term are displayed as a list of links and not as a list of teasers. Can't find a way to do this with Taxonomy list. How can this be achieved?

NancyDru’s picture

Try Taxonomy Redirect with this code:

  $tid = 491;
  $items = array();
  $list = taxonomy_select_nodes(array($tid));
  while ($row = db_fetch_array($list)) {
    $items[] = l($row['title'], 'node/'. $row['nid']);
  }
  echo theme('item_list', $items);

NancyDru (formerly Nancy W. until I got married to Drupal)

dmnd’s picture

I think tagadelic would be useful for some people here

PlayfulWolf’s picture

yes, even solve 95% of here mentioned problems... ;)
--
naslenas.com - personal Drupal blog experiment

OneTwoTait’s picture

If it worked... I'm reading this page because it doesn't.

Zythyr’s picture

I got confused after you guys started putting in PHP code.

I am trying to have Views create a page for me to list all the terms in a certain vocabulary. But I can't figure out how to do it. I am guessing based on reading through the comments using the Views module isn't the right choice.

I added a Vocabulary called "Classified", and underneath it, I added all the terms in a hierarchical fashion. For example: For Sale >> Electronics, Clothes, Books, etc. Jobs >> Accounting, Finance, etc. All I want to do is have all these terms listed on a page so users can see different categories, click on them, then see all the postings other users have made. I used the Views module to list all the terms but it won't work. I set it to create a page, and for the Fields, I put in Taxonomy All Terms...

general need’s picture

I'm trying to do the same and am amazed at how hard it is.

NancyDru’s picture

I think you'd be better off with Taxonomy List. But that is just my opinion.

general need’s picture

Hi Nancy, I had checked out Taxonomy List and viewed your demo page. Hopefully, constructively, your demo page did not really show off Taxonomy List as the solution I was after. I think it was the jumble of images etc. I have since installed it and applied it to a taxonomy with no images. Indeed it appears to actually go a long way to meeting my needs. Thanks for the module.

emwu25’s picture

Did you figure out your answer yet? I'm still having problems with similar issue.

---------------------------------------------------------------
Tungsten Ring

AntiNSA’s picture

HI----

Please Nancy drew I need you help! I have been downloading every taxonomy module I can find.

I have several aggregated news feeds which contain numerous taxonomy tags from several taxonomy vocabularies.

Now,

I have a Taxonomy category "Business"

And several nodes in that category.

CAT Business
Node A
Term1
Node B
Term 1
Term 2
Node C
Term 1

I am trying to create a sortable list which I can

1) Change the CAT Selection ---- IE Business / Health / Science (with the option of multiple categories or all even?)
1a) Chose the cat of the term you are interested in learning about

2) List the tax term with the total number of times it is listed in a node... for the above example it would be
Term 1 (3)

3) Sort the list from ascending to descending or vice versa
Term 1 (3)
Term 2 (1)

4)Allow a filter to be added which would limit the time period by node published date

5) allow you to set the number of terms to display with paging option.

NancyDru’s picture

I don't think you are going to find one that does all that. I suspect you are going to need a combination of a few modules and a custom one.

mariner702’s picture

I’ve been trying to create navigational structure similar to that of craigslist—utilizing the drill down approach. The closest module I’ve found to do something like this is the Directory module but it doesn’t isolate the terms. I’m curious, is this thread discussing something like what I’m describing?

ev_rowe’s picture

I have been trying to do essentially the same thing. All I really want is a simple way to list a given set of taxonomy terms in a vocabulary…or, basically I want a way to list all of the terms that are children of a parent term. It seems like a really simple, straightforward function that ought not be such a pain, but for all of my digging around in both modules or code snippets, I cannot find a simple solution. It is baffling to me that it's so difficult to find a quick bit of PHP that accomplishes this which I can then drop into a template file. Can anybody help me out with this? The sooner the better. Thanks!

silkscreen’s picture

I was looking for a way to list nodes associated with taxonomy, in the same way that they appear in a book hierarchy. My trouble was that the nodes themselves would not show up in the drill down tree structure as links with most of the taxonomy modules.

Anyhow, i thought this tutorial was great (below), and now by using views i have a pretty nifty listing, its not collapsible, i have the listing in a table, with an associated menu item, but it works ok for me.

Still need to learn more about it, but there are some sorting options with views that are pretty neat that I want to figure out. If anyone else is using views, how did you make it work?

http://realtech.burningbird.net/content-management/planet-drupal-entries...

red18’s picture

Views does this so easily.

Just create a view of type ' Term' (the default is 'Node'). Then add 'Taxonomy Category' as as a filter, choose which Vocab to use. Add 'Term Name' as field. Finally make a display block and you are done.

NancyDru’s picture

For those who are still on Drupal 5, Views (1) does not do it well. Views2 in Drupal 6 does.

yeeloon’s picture

Hi,

I'm not sure where to post this, but hope someone can help..

How can I display the below all the terms & subterms under the Catalog vocabulary with proper indentation? The order/weight is similar on how it is stored under the Catalog vocabulary. Actually this is similar to the Ubercart's Catalog block, but I need just a simpler one to place in on the block. The ubercart's code is very complex and don't know how to retrieve it.

Any help would be welcome. Thanks!

Catalog

Clothing (6)
- Dresses (3)
- Sweaters (1)
- Tops (1)

Bags (2)
- Backpacks (1)
- Hobos (1)

Example screenshot

- yeeloon

NancyDru’s picture

yeeloon’s picture

Finally thanks to your Taxonomy List module, I've been able to display the terms & subterms correctly. Awesome stuff!

Thank you NancyDru!

n_nelson350’s picture

DO it with Views using 'term' type - the Taxonomy list will be printed.

hixster’s picture

@n_nelson350 - if you know a way to list only the top level terms in a user defined vocabulary with Views please share here. I don't think it's possible.

Drupal Web Designers Surrey South East England www.lightflows.co.uk

spgd01’s picture

I found many solutions for different ideas:

Simple list of taxonomy terms

Modules to look at:

Using Views:

  • Use argument in views: "Taxonomy: Term Name" where the default is "Summary, sorted as view", and title is %1
  • Use Filters: Use "Term" view type instead of a node, then a "fields" of "Taxonomy Term", then use a "filter" for the vocabulary or term of chose

A list of terms with nodes and teasers under each term, or more

Use Views to group:
Create a node view type with the "fields" for "node title", "node teaser", and "taxonomy term." In your basic Settings box, click on "Style" and select "list" or perhaps a "grid" (then save). Then, click on the "style" settings icon again next to "lists" or the "grid." There you can select a grouping field. If you have set up a taxonomy, select that vocabulary. Click update, and you should be all set.

shriji’s picture

Thanks

Balbo’s picture

subscribing for the useful thread.

ressa’s picture

Add Taxonomy: Term Node Count to display number of nodes tagged with that term

jh3’s picture

This helped me out and has some neat little snippets. Thanks!

luke.perring’s picture

I have spent millenia searching for a way to implement my desired catalogue, which would be as follows.

(Block 1)
"Shop by Category" (vocabulary)
term 1 (node count in brackets)
term 2 "
term 3 "
etc.

(Block 2)
"Shop by Brand" (vocabulary)
term 1 (node count in brackets)
term 2 "
term 3 "
etc.

I thought I'd done it with views, until I added more than one product per term. This produced the duplicate problem mentioned somewhere above. Then I tried using the module "Taxonomy List", and the block it outputs. This didnt work for me either, as the fonts were undesirable, and I couldn't seem to get it to display node count belonging to each term. THEN I FOUND THIS THREAD! The php code provided by jastraat and modified by NancyDru seems perfect, however I cannot get it to show! when I put the code into a block, with php code as the selected imput format, the block doesn't appear. What could be wrong?

NancyDru’s picture

First, "...as the fonts were undesirable..." should be fixable by overriding the CSS. "...display node count..." is a setting.

When a block does not show, it is usually because it is not returning any data or the role/visibilty settings are not correct.

mudatrust’s picture

how do i Using view to display taxonomy as search in a page or in a block ? please any body who can help me the step