Hi,
I'm a Newbie and I've spent many hours in trying to find a solution but right now I'm totally lost. I found many topics but I'm still not able to get this going. Maybe it is just one click but I don't know where to do it!
I'm using Drupal 4.7.3 on linux and with MySQL version 4.1.21

I would like to display all sub-terms of a term when clicking on that term in my navigation menu or somewhere else.
In other words I would like to replace "There are currently no posts in this category." with a content table showing me simply the sub-terms but not the nodes or the content of them.
It shall look more or less like this:

  • Term 1
    • Sub-Term 1.1
    • Sub-Term 1.2
      • Sub-Sub-Term 1.2.1
      • Sub-Sub-Term 1.2.2
    • Sub-Term 1.3

I found many comments recommending the category module but I had too many other problems with the category module, so I would like to use taxonomy as I'm running out of time.
The views module is apparently also very useful but it is too confusing to me at the moment to solve my problem unless someone could give me some advice or a short 'to-do-list'.
Another possibility seems to be to insert some snippets into the taxonomy.module. A topic like this one
http://drupal.org/node/34256
explains what to do, but I don't know how to use it (maybe it even outdated). Where and how do I have to implement this PHP-Snippet?
The weird thing is that it works for my vocabularies. For each of my vocabularies there are created automatically blocks (in admin>blocks) which display all terms and subterms of the vocabulary when they are enabled (although there are displayed some numbers behind the terms which I would like to omit as they seem to count all related terms instead of only the sub-terms). But I haven't found a possibility to do this for terms.

I hope I've expressed myself not too confusing but I really need some help with that. Could someone please give me some advice?

Comments

venkat-rk’s picture

Try taxonomy context without enabling the description.

DKIWI’s picture

Don't know whether I'm doing something wrong. I have 'show subterm info' (Show listings of subterms (sub-categories) for current term) enabled but it still states:

"There are currently no posts in this category."

I see some new blocks (in admin>blocks) that have names like: Context for 'Vocabulary-name'
But there are no blocks for the terms.

Is there something else I should consider as well?

TheWhippinpost’s picture

Have a look at the block snippets section.

You might not want them to show-up in blocks but you might be able to whack the code into your template.

Alternatively, you might wanna try and play with this snippet below which has not conditions for testing which page it should display (and others too, I'm sure). In other words, it's a start (and possibly even what you're looking for, I dunno), but I don't want to lead you into another time-drain so it's up to you.

<?php /* Use print $categorylink in template for correctly aliased category links */
  $categories = taxonomy_node_get_terms($node->nid);
	if ($categories) {
		$termlink = '<ul>';
	  foreach ($categories as $category) {
			 $categorylink = l(t($category->name), 'taxonomy/term/' . $category->tid, array('title' =>$category->name), NULL, NULL, TRUE, TRUE) . "\n";
		$termlink .= '<li>' . $categorylink . '</li>';
			}
		$termlink .= '<ul>';
	  }
 ?>

Place <?php print $termlink; ?> wherever you want the list of terms to show.

I quickly just tested it in my node.tpl.php file but I suspect you will need to put conditionals in (as hinted above) and play around with it to suit your layout-needs... or look to place it within a template.php

I'm posting this in a rush I'm sorry, but HTH

PS.... I wasn't a fan of taxonomy context but it may've been updated since so I don't know.

Mike

DKIWI’s picture

Thanks for the snippet, I will give it a try but I'm not a programmer and don't know exactly how to use your code or where to place it. Would you mind to explain it a little more in detail?
Thanks anyway.

TheWhippinpost’s picture

don't know exactly how to use your code or where to place it. Would you mind to explain it a little more in detail?

It's better to ask more specific questions - I may not have explained it fully enough because I no longer have a newbie's eyes, and unless you try it, you won't be able to ask me specifics.

All I can do is repeat what I've already said and that is, place it in your node.tpl.php file and try it.

Remember, I said it may be a start, it probably isn't a full solution for what you are looking for but at least it might set you on the right path to ask further questions to get it looking how you want.

You have a lot of taxonomy-related modules, are they ALL enabled?

I feel your frustration, adding lots of modules in search of a solution is a path many here probably start down when we begin. Some things are overly complicated to perform and the frustration can be deeper when modules are either buggy or not kept up-to-date... but it is, what it is.

I suggest you disable modules you know don't do what you want as they maybe either interfering with the process, or adding another layer of confusion to your thinking.

Mike

venkat-rk’s picture

Have you created any content? The 'there are currently no posts...' message suggests that you haven't.

As for the terms appearing in the blocks, the blocks don't show up until you have created at least one node and tagged them with the term. Please see http://drupal.org/node/76558

DKIWI’s picture

I had already created two pages but tagged them only with the "sub-sub-term 1.2.1".
So I tagged them now as well with the "sub-term 1.2". When I click on this sub-term 1.2, I can see the content of the two pages but not a listing of its sub-terms.
Its in fact just the contrary from what I want. No content but a subterm listing.

I've enabled the 'show listings of subterms' and disabled 'Show additional information' in taxonomy_context but the result is still the same.

Now I have even the problem that the content of my two pages is shown in my vocabulary and the subterm listing has fallen below this content (although the weight of the subterm-listing-block is at -10).
Really weird, maybe I don't see the wood for the trees but I really don't know what to do.

venkat-rk’s picture

Trying to understand your question better...

The weird thing is that it works for my vocabularies. For each of my vocabularies there are created automatically blocks (in admin>blocks) which display all terms and subterms of the vocabulary when they are enabled (although there are displayed some numbers behind the terms which I would like to omit as they seem to count all related terms instead of only the sub-terms).

This isn't default taxonomy behaviour. Can you tell what other modules you are using?

DKIWI’s picture

Here are the enabled modules:

aggregator
archive
article
blog
blogapi
book
chatbox
comment
contact
flexinode
forum
freemind
help
imce
locale
menu
nice_menus
node_type_filter
page
path
pathauto
poll
profile
search
statistics
story
tagnode
taxonomy
taxonomy_block
taxonomy_browser
taxonomy_context
taxonomy_dhtml
taxonomy_menu
taxonomy_switch
throttle
tinymce
tracker
upload

I've added another Test-Vocabulary and immediately a new block (called Test-Vocabulary) was created in administer>blocks.
After that I added two terms to the Test-Vocabulary (Test term 1 and Test term 2) and enabled the Test-Vocabulary-Block.
This it what it shows when I click onto the Test-Vocabulary link:

Test-Vocabulary
There are currently no posts in this category.
Test-Vocabulary
- Test term 1
- Test term 2

venkat-rk’s picture

I've added another Test-Vocabulary and immediately a new block (called Test-Vocabulary) was created in administer>blocks.

I suspect this is the taxonomy_block coming into play. It might be useful to disable all the taxonomy helper modules (or at least taxo_block, taxo_dhtml and taxo_menu as these are the ones that add blocks) and then try out taxonomy context.

DKIWI’s picture

I disabled all taxonomy modules but taxonomy and taxonomy_context. Immediately all my menu items (the vocabulary and term I've created) in the navigation bar disappeared.
I created a new Vocabulary with terms and put them under my primary links (thus having Tax_menu disabled).
Now I enabled Tax_menu and all my menu items appeared again in the navigation bar plus the newly created Vocabulary with its terms (which is as well in my primary links).
And now I realised the first time that the two links (primary vocabulary link and the tax_menu vocabulary link) show different contents! Well, I see that they link to different directories, namely taxonomy/vocabulary/101 and taxonomy_menu/101, but I thought that they would display the same content somehow!?
Isn't that a bit ambiguous? I mean tax_menu creates a new link with the same name but points to different content. It seems to me that the tax_menu links point to a directory where all the content (or content-links?) of the sub-terms is stored. This content is hence displayed under a tax_menu link.

As I would like to have a subterm-listing wihtout any content displayed I will keep tax_menu disabled unless I'm doing something wrong. Please tell me if it is so!
In order to get the subterm list I enabled in administer>blocks the 'Content for Vocabulary-name' and now I can see a subterm listing. Awesome! Thanks a lot!

But I still have a problem. Above my subterm-lisiting the terms are displayed another time. (I've disabled all tax_context options if this makes a difference at all)

It is displayed this way:

TestVoc

» edit
TestTerm

» read more | edit
TestTerm2

» read more | edit
TestVoc

* TestTerm
* TestTerm2

I would like to have it this way:

TestVoc

* TestTerm
* TestTerm2

Is there a possibility to omit the upper part and to display only the "Content for TestVoc"-Block which contains the subterm-listing?

TheWhippinpost’s picture

I think I'm a bit confused and unfortunately I don't have much time. But I think I have picked out the skeleton of what you are saying.

I see that they link to different directories, namely taxonomy/vocabulary/101 and taxonomy_menu/101

Yes, this is a bug with tax_menu I believe. It is creating another alias (for its own internal use) and, for whatever reason, it's not instructing the system correctly.

Only last night did I post a work-around to handle this, but for a different use - You can view it here: Use Taxonomy Menu Aliased Links

This should hopefully convert the 'taxonomy/' URL, to the 'taxonomy_menu/' URL... but I can't guarantee it will work for your situation.

I would like to have it this way:

TestVoc

* TestTerm
* TestTerm2

Is there a possibility to omit the upper part and to display only the "Content for TestVoc"-Block which contains the subterm-listing?

If I'm reading you correctly, I did suspect you would eventually end up with this scenario. To solve this, we have to go to the theming level, and there are several directions you could take.

Briefly, when you arrive at these pages, the 'node.tpl.php' file (in your theme's folder), is wanting to print-out all the teasers for all the nodes listed for the term that page relates to, that's why you are getting repeated text... even if you don't have teasers enabled.

You could hack your 'node.tpl.php' file by including all sorts of conditional display parameters but I suspect it would be easier to look at creating a seperate file called 'template.php' to do this work.

I don't think it would actually be hard - Theoretically, you may be able to take some of the code found in the link above I provided, and shape it to work in the template file so that it over-ride the PHPTemplating Engine - Try a search here for that phrase (in bold) to learn how.

That's all I have time for sorry, see how you go and report back.

Mike
------------------------------------------------------------------------------------------
A simple thanks to those that help, a price worth payng for future wealth.

DKIWI’s picture

First I need to say that I have little knowledge in programming so

take some of the code found in the link above I provided, and shape it to work in the template file

is something almost impossible for me. (I tried to read the relevant topics in the handbook but I don't know how to use the descriptions).
Nevertheless I tried at least to follow the steps on your new post.

-I enabled tax_menu, pathauto and Clean URL

-I went to .../themes /voodoo_dolly/node.tpl.php

-Couldn't find this line:

<?php /* $Id: node.tpl.php,v 1.4.2.3 2005/11/30 21:06:47 robinmonks Exp $ */ ?>

but it seems to me not to be of much importance, right?

-So I copied your last snippet and inserted at the top of all the code

-After that I replaced:

<span class="taxonomy"><?php print $terms ?></span>

with

 <?php if ($links): ?>
<p><?php if ($terms): ?> <span class="taxonomy">Posted in <?php print $categorylink ?></span><?php endif; ?></p>
<?php endif; ?> 

saved it and had a look whether it worked. But unfortunately I couldn't find any change to the previous functionality of the tax_menu.

The other thing is this here. You said:

the 'node.tpl.php' file (in your theme's folder), is wanting to print-out all the teasers for all the nodes listed for the term that page relates to, that's why you are getting repeated text... even if you don't have teasers enabled

Where can I disable teasers? Or are they disabled by default and the 'node.tpl.php' file creates the problem you mentioned?

I think I won't be able to solve this problem having to program a snippet myself :-(

TheWhippinpost’s picture

Apologies for not getting back to you sooner but my broadband has been (and still is) down... so I decided to capitalise on the enforced isolation and take a break.

So now I'm a bit disjointed as to where I left-off (and where I was headed!) but let me try and tackle some of your easier issues.

I tried to read the relevant topics in the handbook but I don't know how to use the descriptions

I'm not sure I understand what you mean by that (or whether you meant that to be relevant, possibly not.).

Couldn't find this line:

/* $Id: node.tpl.php,v 1.4.2.3 2005/11/30 21:06:47 robinmonks Exp $ */

but it seems to me not to be of much importance, right?

Not for this exercise, no.

-So I copied your last snippet and inserted at the top of all the code

-After that I replaced:

print $terms

with...

Snipped...

Right, well that snippet should have converted the path problem you mentioned above, to the correct alias instead of the problem of where you said:

taxonomy/vocabulary/101 and taxonomy_menu/101, but I thought that they would display the same content somehow!?

... so are you saying that the paths are still not working correctly?
(Mouse-over the link and check the path in the status bar of your browser (bottom-left)).

Disabling teasers is a bloody good question! I've not had the need to do this so I really don't know - Just assumed you could. Might be worth a search - I'm sure there must be a way.

I know this will probably add to your frustration but I don't think you will have any choice but to get your hands dirty and learn a few tricks of conditional theming - By that I mean: sniff out what page is being displayed, if it's a directory page, show a page with your terms on it, otherwise... content (I presume).

To do that, you should learn the basic principle of using a template.php file and (within it) over-riding the PHPTemplate Theme Engine to switch to your desired template that outputs your terms in the way you want.

As a quick-tip/start: Make a copy of node.tpl.php and rename (the 'node' bit) to whatever suitable: example.tpl.php

Within your template.php file, create conditions that sniff-out the page a user is browsing and for which you wish to display your example.tpl.php - if matched, instruct the system to switch to the example.tpl.php file. There are instructions for doing just that (try the handbooks) so don't feel too overwhelmed... if y9ou can follow instructions, you'll be OK).

Within the example.tpl.php file, you'll need to essentially strip-out all the extraneous content/code that remains inside your example.tpl.php file leaving just the code that spits-out your links (The code in post #3 above might help you with that, together with the tax_menu "fix" (if working and/or needed)).

A pain? I understand but there's no "out-of-the-box" option to do what you want, but it is do-able if you're determined.

ADDED: Guess what! Just found this that might be reet up your street:

Directory

Not used it but good luck.

Mike
------------------------------------------------------------------------------------------
A simple thanks to those that help, a price worth payng for future wealth.

DKIWI’s picture

I thought I would get no responses any longer and tried to find another solution. Unfortunately time is over now and the system needs to be handed in. It will be no problem as other people will get the opportunity to work on this issue and the project advisor does'nt see this as major problem. Nevertheless I am going to refer to your posts to give them some hints how to tackle the problem.

Again thank you very much for investing so much time!

If you are interested to see another solution that might work (but did not for me) please see following post:

http://drupal.org/node/43130#comment-110844

Cheers

jmav’s picture

You could also use http://drupal.org/project/contemplate Content Templates (Contemplate) module.
There you can change how you can see teaser for each content type.

venkat-rk’s picture

Disabling teasers is a bloody good question! I've not had the need to do this so I really don't know - Just assumed you could. Might be worth a search - I'm sure there must be a way.

In the category module, this is as simple as checking or unchecking a 'category_display' setting both for containers and categories. You can then replace the teasers with custom stuff or a view. Just posting this here as part of my effort to document the differences between taxonomy and category. Not meant as a direct response to your question:-)