Using Views to Generate A Taxonomy List

Rob_Feature - March 15, 2007 - 15:50

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?

Maybe I didn't get your

Anonymous (not verified) - March 15, 2007 - 16:44

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

In a block

Rob_Feature - March 15, 2007 - 17:59

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

Access Denied

NancyDru - March 21, 2007 - 22:51

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

A little more clarification -

jastraat - March 15, 2007 - 19:38

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.

This sounds good

Rob_Feature - March 15, 2007 - 20:20

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, To create a block with

jastraat - March 15, 2007 - 20:47

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:

<?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);}
?>

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.

Perfect

Rob_Feature - March 16, 2007 - 00:53

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

*grin

jastraat - March 21, 2007 - 14:52

Glad to help.

Many thanks for this code

Quint - July 16, 2007 - 04:06

Nice and simple solution.

Quint

Works great!

jiangxijay - July 26, 2007 - 00:32

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

Nice, but one problem I found...

colkassad - November 10, 2007 - 11:47

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?

That is correct

NancyDru - November 10, 2007 - 14:03

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

Yep :)

colkassad - November 10, 2007 - 14:16

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

BTW

NancyDru - November 10, 2007 - 14:22

Your site is great

skyredwang - March 28, 2008 - 06:52

Thanks for your information and work.

BTW

NancyDru - March 28, 2008 - 13:25

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

Same problem

Didaci - November 29, 2007 - 14:02

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.

Unfortunately, no

NancyDru - November 29, 2007 - 14:33

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

Thanks!

pierrelord - December 11, 2007 - 01:24

Thanks!

Thank you.

excell - March 1, 2008 - 15:40

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...

<?php$vid = 1;  // Set the

mz906 - April 2, 2008 - 14:56

<?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);}
?>

can you do this using the views UI?

lol

jfall - April 2, 2008 - 17:16

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.

I am experimenting with

mariagwyn - April 7, 2008 - 18:57

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 - April 2, 2008 - 19:35

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

Shouldn't this be...

willdashwood - April 20, 2008 - 17:27

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

failed

Viranil - April 16, 2008 - 20:08

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?

This has answered my

anotheraviator - May 16, 2008 - 21:21

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.

Maybe

NancyDru - May 16, 2008 - 22:15

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)

Vocab list filtered by content type

johnphethean - May 29, 2008 - 20:39

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...

Yes

NancyDru - May 30, 2008 - 00:20

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

Betsson Thank you...

dreamydell - November 1, 2008 - 11:11

Hey there. I'll try to give

chriswb - March 15, 2007 - 20:08

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.

Not quite...

Rob_Feature - March 15, 2007 - 20:16

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, Sorry, I have no idea

chriswb - March 15, 2007 - 22:53

Bob,

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

The reason...

mikemccaffrey - May 16, 2007 - 19:00

...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

Filtering taxonomies

jasio - May 12, 2007 - 11:33

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).

I think this is included in

catch - March 16, 2007 - 10:52

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

Would the taxonomy_dhtml

reggie75 - March 22, 2007 - 04:56

Would the taxonomy_dhtml module be of any use?

http://drupal.org/project/taxonomy_dhtml

Hi, I've done this with

lukathonic - March 27, 2007 - 20:55

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 -

Incredible

NancyDru - March 28, 2007 - 00:08

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

Just Views Code

Rob_Feature - March 28, 2007 - 13:31

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

I've been having the exact same problem

rdurrette - March 29, 2007 - 23:36

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!

Views is definitely the way ..

illSleepWheniDie - February 1, 2008 - 11:01

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

Non-Developers

leoklein - February 4, 2008 - 14:12

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.

Views needs nodes

NancyDru - February 4, 2008 - 14:52

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

Shows Tax Terms in Use

leoklein - February 4, 2008 - 15:03

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.

excellent!

pcs305 - March 24, 2008 - 19:00

Following this discussion

Landcentre

Willdex - April 4, 2007 - 05:03

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 - April 4, 2007 - 05:17

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.

Ditto

femrich - April 4, 2007 - 08:43

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

I'm tracking this thread

Tom-182 - April 4, 2007 - 14:12

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

http://www.geektips.net

Tag

joshua_cohen - May 10, 2007 - 16:17

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

This is the answer to get a taxonomy list!

kuahyeow - April 9, 2007 - 06:03

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

what does the 1% do exactly?

bjraines - April 11, 2007 - 16:25

what does the 1% do exactly?

The %1 puts the taxonomy

joachim - April 17, 2007 - 21:48

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.

Excellent :) Is there a way

joachim - April 17, 2007 - 21:42

Excellent :)

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

yes

NancyDru - April 18, 2007 - 03:03

How?

joshua_cohen - May 12, 2007 - 02:02

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

Nice, this solved my issues,

eferraiuolo - June 12, 2007 - 17:38

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

Wow

goldentoque - April 11, 2007 - 16:11

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

But What to Edit?

Dustin Boston - May 3, 2007 - 06:48

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?

View

shrop - May 21, 2007 - 21:59

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

Same problem

Aren Cambre - July 4, 2007 - 06:08

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.

I fixed that ..

illSleepWheniDie - February 4, 2008 - 02:42

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!.

Other fields in the view

iaminawe - April 7, 2008 - 15:17

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

That's a nice example for us

SirMoby - May 14, 2007 - 17:46

That's a nice example for us poor hacks.

Thanks

Hmm...

NancyDru - May 14, 2007 - 20:27

Not indeed...

rtandon - August 29, 2007 - 19:10

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)

Thanks

NancyDru - August 29, 2007 - 21:46

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

Refining this list by node type

newswatch - September 10, 2007 - 16:32

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:

<?php
  $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);
?>

Well, actually

NancyDru - September 11, 2007 - 02:01

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

refining by node type

As If - February 5, 2008 - 10:52

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

Hmm...

NancyDru - February 5, 2008 - 13:06

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

Hmm again...

As If - February 6, 2008 - 04:21

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

Hmm...

NancyDru - February 6, 2008 - 04:35

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

Count but not showing node-title/body

Summit - February 6, 2008 - 08:18

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

Yes! precisely like that, I

Summit - February 6, 2008 - 13:19

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

Here you go...

NancyDru - February 6, 2008 - 15:25

<?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

Altered panels_taxonomy_child_terms_list

Summit - February 7, 2008 - 13:51

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

You could

NancyDru - February 7, 2008 - 14:36

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

You could

NancyDru - February 7, 2008 - 14:38

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

Hi Nancy, I leave it than. I

Summit - February 7, 2008 - 14:49

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

Hi Nancy, Do you know how I

Summit - February 18, 2008 - 09:49

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

CSS

NancyDru - February 18, 2008 - 15:08

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

Hi Nancy, This is my code.

Summit - February 18, 2008 - 15:52

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

easy

NancyDru - February 18, 2008 - 19:16

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

Hi Nancy,It is not

Summit - February 18, 2008 - 20:15

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

Refresh Garland

NancyDru - February 18, 2008 - 22:04

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

Hi Nancy,I will try this!

Summit - February 19, 2008 - 08:45

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

Try this

NancyDru - February 20, 2008 - 13:31

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

(thought balloon)

As If - March 14, 2008 - 06:01

how narrow can these comments get?

Pretty narrrow

NancyDru - March 14, 2008 - 13:02

I can't stop!

As If - March 15, 2008 - 03:05

I can't stop!

Oh My!

NancyDru - March 15, 2008 - 04:56

OUCH!

As If - March 16, 2008 - 03:27

OUCH!

Shedding the pounds!

jyg - March 20, 2008 - 20:09

Shedding the pounds!

Skinny

NancyDru - March 21, 2008 - 03:08

Wish I could get this thin!

Jack Sprat could eat no fat!

jyg - March 31, 2008 - 16:58

Jack Sprat could eat no fat!

norrowest

pharma - September 17, 2008 - 02:12

i think so

A very long thread ever and

gausarts - September 11, 2009 - 16:26

A very long thread ever and narrowest comment : D

love, light n laughter
gausarts

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

pr0test0r - November 9, 2008 - 17:01

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;

Thanks Nancy!

joyltd - July 16, 2009 - 13:50

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.

Hi, showing what code you

Summit - July 16, 2009 - 14:05

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

Greetings,
Martijn
if you appreciate e-development work, please place a link from your site to www.trekking-world.com

Of course!

joyltd - July 21, 2009 - 13:55

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:

<?php
      $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.

Didn't get the view to work ..

florianr - September 30, 2007 - 03:02

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?

Ok so... I've managed to get

adshill - May 2, 2007 - 21:24

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!

Use Refine Taxonomy

justin_d - May 14, 2007 - 11:57

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.

Problem with one word length terms

MrPrise - May 24, 2007 - 20:34

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...

Interesting Thread

dabro - July 26, 2007 - 04:23

Bookmarking, I want to try this.

Subscribing

droople - July 26, 2007 - 19:15

Will need this one day

Subscribing too

Suzy - February 7, 2008 - 09:55

..

you can use views_fusion?

dindon - July 27, 2007 - 19:25

you can use views_fusion?

Just Traking

diegohermes - July 30, 2007 - 12:04

Very useful.

I gotta try this

jjjames - November 8, 2007 - 09:39

I gotta try this

Well...

NancyDru - July 30, 2007 - 21:05

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

Taxonomy List Is Awesome!

wonder95 - August 19, 2007 - 05:14

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 - August 19, 2007 - 14:35

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

Subscribing and Sample View - Taxonomy Photo Gallery

mkmckinn - September 21, 2007 - 22:41

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;

Thank you so much!

anschinsan - August 17, 2007 - 20:32

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

Subscribing

colan - August 22, 2007 - 19:52

-

Is there any way can

nishit - August 24, 2007 - 18:25

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

Subscribing as well...

aswalla - August 30, 2007 - 21:39

Subscribing as well...

Subscribing

Erdbert - September 3, 2007 - 12:17

very helpful

subscribing

wbmangy - November 27, 2007 - 18:14

-

Weird...

Pol - September 3, 2007 - 20:20

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-

I speak too quick...

Pol - September 3, 2007 - 21:16

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-

Error

newswatch - September 10, 2007 - 16:06

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

fix

trevorleenc - February 9, 2008 - 12:54

replace &gt; with >

Very interesting thread...

cyp25 - September 22, 2007 - 09:43

Bookmarking too, will try this...

Ciprian M.
Webdesign & Multimedia

Did one of you also solve

funkyfrieder - September 26, 2007 - 07:58

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?

Related forum post

femrich - October 25, 2007 - 07:23

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....

How can I list terms from another vocabulary?

dcoder - November 12, 2007 - 01:10

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*

I'd suggest starting a new

femrich - November 12, 2007 - 10:04

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

Prophecy come true

harrypark - March 8, 2008 - 03:10

Yeah this discussion has gotten pretty long

yeah, the thread that goes

Quint - March 8, 2008 - 22:03

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

Is there a way to unsubscribe from a thread?

This is exactly what I'm looking for

dejbar - April 29, 2008 - 01:49

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.

Have you considered...

NancyDru - April 29, 2008 - 02:20

How to change this

Kalian - November 16, 2007 - 14:36

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?

Interesting concept

NancyDru - November 16, 2007 - 16:49

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

Check out A List Apart:

ep - November 16, 2007 - 17:27

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

EP

Thanq

Sree - November 16, 2007 - 18:09

that a useful link ....

thanks

dudeoflife - November 10, 2009 - 22:50

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

ep, thanks for link, it's

Kalian - November 18, 2007 - 21:23

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.

OK

NancyDru - November 18, 2007 - 21:51

I will expose the code, or you can send me you email address.

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

Hi Nancy, If I want to

mzafer - November 21, 2007 - 05:27

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

Hmm...

NancyDru - November 21, 2007 - 13:15

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

I'll take a look at the

mzafer - November 21, 2007 - 22:36

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

Okay

NancyDru - November 22, 2007 - 04:51

<?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

Thanks Nancy.. that

mzafer - November 22, 2007 - 16:02

Thanks Nancy.. that worked

Zafer

Hi Nancy, good snippet,

soter82 - March 1, 2008 - 16:06

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

How to?..

Kalian - November 21, 2007 - 12:09

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?

Depth

NancyDru - November 21, 2007 - 13:12

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

Count

Kalian - November 21, 2007 - 16:34

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

Try it this way

NancyDru - November 21, 2007 - 17:21

It works

Kalian - November 22, 2007 - 07:57

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.

Code should be

DesignWork - December 7, 2007 - 09:21

Hi Nancy,

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

Dirk

I have so little hair left to pull out...

dhovey - January 30, 2008 - 17:40

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!

Nodes from subcategories

CharlieR - November 25, 2007 - 17:36

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)

Try to use

Kalian - November 25, 2007 - 17:49

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).

Thanks for the quick reply

CharlieR - November 25, 2007 - 19:49

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.

Its working now

CharlieR - November 25, 2007 - 20:54

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

Hi to all! I'm working with

vanessa_83 - November 28, 2007 - 09:58

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.

Hi 1)I have the same problem

funkyfrieder - December 4, 2007 - 07:42

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

views

homeshop - December 6, 2007 - 11:26

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

Some Help needed

DesignWork - December 7, 2007 - 09:32

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

Thanks jastraat for the PHP

Borromini - December 19, 2007 - 22:38

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.

Subscribe...

STyL3 - December 24, 2007 - 16:32

+1

- Subscribing -

Devis - January 2, 2008 - 15:21

- Subscribing -

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

--
Italy

Awesome! Subscribing.

msameer - January 3, 2008 - 15:26

Awesome! Subscribing.

subscribe

timb - January 4, 2008 - 22:53

- bottmanbros.com

i did it like this

funkeyrandy - January 16, 2008 - 07:09

$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];
}
}

?>

Imma In

trevorleenc - January 26, 2008 - 05:12

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!

just subscribing Aleph

aozuas - January 26, 2008 - 13:02

Hi, This thread is very

Summit - February 5, 2008 - 12:37

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

Hi Martijn, I think the

mzafer - February 10, 2008 - 04:32

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

I got this from

giggler - February 12, 2008 - 07:38

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>';
?>

nice

trevorleenc - February 12, 2008 - 10:43

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...

bad link

trevorleenc - February 12, 2008 - 10:55

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

:)

oops, I was too busy

giggler - February 12, 2008 - 15:09

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.

no worries on the url :) the

trevorleenc - February 12, 2008 - 20:08

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

I've just installed taxonomy

giggler - February 12, 2008 - 21:48

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...

If I recall

trevorleenc - February 12, 2008 - 23:02

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 :)

sadly

trevorleenc - February 12, 2008 - 23:04

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 :)

Huh?

NancyDru - February 13, 2008 - 00:54

you're right

trevorleenc - February 13, 2008 - 02:20

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...

I've changed the menu to use

giggler - February 17, 2008 - 03:31

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:

<?php
$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>';
?>

Try this for efficiency

NancyDru - February 17, 2008 - 14:42

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

Thanks Nancy... Do you know

giggler - February 17, 2008 - 22:56

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?

Not off the top of my head...

NancyDru - February 18, 2008 - 01:39

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

ok, I found this code which

giggler - February 18, 2008 - 02:41

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.

Which code?

NancyDru - February 18, 2008 - 04:34

This code, but I do need to

giggler - February 18, 2008 - 18:28

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);
?>

This code, but I do need to

giggler - February 18, 2008 - 18:29

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...

This is what i was looking

ranavaibhav - June 9, 2008 - 01:02

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

Making a collapsible directory

sockah - March 3, 2008 - 21:19

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).

Have a look here

awasson - March 14, 2008 - 15:27

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)

This was pretty easy to do with my taxonomy vocabulary.

kirikintha - March 4, 2008 - 20:12

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;

It doesn't

NancyDru - March 4, 2008 - 22:01

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.

OOPS

kirikintha - August 15, 2008 - 15:49

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!

How to display all taxonomies and nodes in order?

yeeloon - March 13, 2008 - 06:45

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

Take a look

NancyDru - March 13, 2008 - 12:03

Thanks!

yeeloon - March 14, 2008 - 09:19

Hi Nancy,

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

Cheers!
yeeloon

yeeloon...

jfall - March 15, 2008 - 06:46

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

Show all nodes belonging to top level parent

anotheraviator - July 8, 2008 - 21:54

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.

Take a look

NancyDru - July 9, 2008 - 02:13

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)

Fantastic!

awasson - March 13, 2008 - 07:40

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

excellent thread!

pharma - March 21, 2008 - 13:35

excellent thread!

About the Nancy code

doomed - March 30, 2008 - 13:34

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.

Which "Nancy" code?

NancyDru - March 30, 2008 - 14:16

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

taxonomy list block

doomed - March 30, 2008 - 14:46

<?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);
?>

Hmm...

NancyDru - March 30, 2008 - 23:31

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

Subscribing - especially

ArjanLikesDrupal - April 1, 2008 - 21:29

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

Try 6.x

NancyDru - April 1, 2008 - 23:13

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

hello

doomed - April 3, 2008 - 21:16

Children Taxonomy list

Summit - April 17, 2008 - 22:05

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

Complex?

NancyDru - April 17, 2008 - 23:11

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

Hi, Nancy helpt me to get

Summit - April 18, 2008 - 14:58

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

subscribing

TheresaM - May 15, 2008 - 17:18

very interesting thread

How to use the taxonomy block for a single content type

nicolaisen_nancy - April 23, 2008 - 02:45

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

Look above

NancyDru - April 23, 2008 - 03:20

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

Subscribing

fletchgqc - April 30, 2008 - 07:30

subscribing

subscribing

SocialNicheGuru - May 15, 2008 - 05:05

subscribing

Subscribing

fallsemo - June 6, 2008 - 14:49

subscribing.

thanks again nancy for this

salviadepot - June 24, 2008 - 19:39

thanks again nancy for this tips

subscribing for sure!

www.salviadepot.com

On term view, get a block with the sister-terms of the same pare

Summit - July 3, 2008 - 22:36

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

Hmm...

NancyDru - July 5, 2008 - 14:15

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)

Hi Nancy,

Summit - July 6, 2008 - 00:34

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

Anyone has Parent looking

Summit - August 31, 2008 - 20:29

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

greetings,
Martijn

TinyTax module

DanielTheViking - August 5, 2008 - 01:40

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."

code you are looking for

viewtest15 - August 27, 2008 - 06:08

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".

<?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>";
    }
   }
?>

---
Play Online

Filter and sort on 2 taxonomy vocabularies?

Taxoman - August 31, 2008 - 09:42

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) "

Is it possible to show a

lesliewu - September 13, 2008 - 18:32

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

Thanks for the quick reply.

lesliewu - September 15, 2008 - 17:36

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?

Hmm...

NancyDru - September 15, 2008 - 17:48

Try Taxonomy Redirect with this code:

<?php
  $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)

tagadelic

dmnd - September 23, 2008 - 21:08

I think tagadelic would be useful for some people here

yes, even solve 95% of here

PlayfulWolf - February 2, 2009 - 12:19

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

If it worked... I'm reading

taite11 - February 24, 2009 - 19:31

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

I got confused after you guys

Zythyr - June 17, 2009 - 06:33

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...

I'm trying to do the same and

general need - July 19, 2009 - 09:45

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

Taxonomy List

NancyDru - July 19, 2009 - 13:30

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

Hi Nancy, I had checked out

general need - July 28, 2009 - 09:42

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.

I'm Still having problems with this

emwu25 - September 2, 2009 - 20:47

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

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

PLease help with the most important drupal problem ever

AntiNSA - September 15, 2009 - 15:45

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.

Oh

NancyDru - September 15, 2009 - 17:52

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.

I’ve been trying to create

mariner702 - November 11, 2009 - 22:48

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?

 
 

Drupal is a registered trademark of Dries Buytaert.