Posted by deepesh on July 23, 2007 at 8:46am
I would like to have Wordpress like category menu in drupal 5, as shown below:
internet(5)
....Google(1)
....Yahoo(2)
....Web 2.0 (1)
....Misc(0)
How to achieve that in drupal ?
I would like to have Wordpress like category menu in drupal 5, as shown below:
internet(5)
....Google(1)
....Yahoo(2)
....Web 2.0 (1)
....Misc(0)
How to achieve that in drupal ?
Comments
I am looking for the same
I am looking for the same function !
I am using a php code in order to make a taxonomy list of a vocabulary id, you can change the code if you know about php because this code display a date "time ago"
<?php$vocabulary_id = 2;
$result = db_query("SELECT d.tid, d.name, MAX(n.created) AS updated, COUNT(*) AS count FROM {term_data} d INNER JOIN {term_node} USING (tid) INNER JOIN {node} n USING (nid) WHERE d.vid = $vocabulary_id AND n.status = 1 GROUP BY d.tid, d.name ORDER BY updated DESC, d.name");
$items = array();
while ($category = db_fetch_object($result)) {
$items[] = l($category->name .' ('. $category->count .')', 'taxonomy/term/'. $category->tid) .'<br />'. t('%time ago', array('%time' => format_interval(time() - $category->updated)));
}
print theme('item_list', $items);
?>
hi
is there a demo for seeing this in action ?
Deepesh Agarwal
Deepesh,
http://MegaLeecher.Net/
I use this code + demo
I use this code:
<?php
$vid = 4; // 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 = "<span>(".db_result(db_query("SELECT COUNT(nid) FROM {term_node} WHERE tid = %d", $term->tid)).")</span>";
$items[] = l($term->name, "taxonomy/term/$term->tid") . " $count";
}
if ( count($items) ) { print theme('item_list', $items);}
?>
here is a demo(right column-second block):
http://www.iran-amirentezam.com
N.Mehrabany
niGraphic web design & photography
N.Mehrabany
niGraphic web design and photography
CSS Formatter & Optimizer
This is what I am after.
This is what I am after. But where do you guys put the code? I tried it in a custom block, with php enabled, placed the block= and the result was being able to see the code in the left side bar. I didn't actually see the block that the code perhaps creates.
I am a beginner. What have I misunderstood?
are you using a HTML editor?
hi,
If your are using a HTML editor, you should go to SOURCE and paste the code there not in the HTML view.
N.Mehrabany
Baruzh web design & programming
N.Mehrabany
niGraphic web design and photography
CSS Formatter & Optimizer
If you are going to put code
If you are going to put code into a Block, make sure it's input is set to "PHP".
Thanks for your replies. My
Thanks for your replies. My problem was that I use FCKeditor and was pasting code into the normal frame rather than the source frame.
Show hierarchy?
Is it possible to include something which shows the hierarchy of the taxonomy? An older v4.7 piece of code I've been using calls on _taxonomy_depth which is now deprecated in v5. It did, however use "--" for each term whose parent was another term.
Thanks!
Answered my own question
Since I found the taxonomy_get_tree function returns the depth of each node, I modified the supplied code above like so:
<?php$vid = 4; // 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)).")";
$termdepth = "";
for ($i=0;$i<$term->depth;$i++)
{
$termdepth = $termdepth . "-- ";
}
$items[] = $termdepth . l($term->name, "taxonomy/term/$term->tid") . " $count";
}
if ( count($items) ) { print theme('item_list', $items);}
?>
Specifically, adding the inner for...loop to add the -- characters one time for each depth level. If you have too many levels and you don't want to return them all to this list, then call taxonomy_get_tree with the fourth parameter being the max depth.
modified for nested lists
Thanks for this, it got me going in the right direction and I found a few more things on the way.
when I got it onto my sidebar it annoyed me a bit that the bullets were all tight to the left so I started messing a bit and got this as a way to build the hieararchy as a series of nested lists. It's basically the same but uses a recursive function call to build the nests.
I'm afraid I've commited a cardinal sin and place markup in the code. Apologies but I'm still finding my way around Drupal. I'd welcome suggestions but I'll post back if I get there first:
For clarity I've left out the count code.
<?php
$vid = 5; // Set the vid to the vocabulary id of the
$terms = taxonomy_get_tree($vid, 0, 0 );
print "<ul>";
foreach ( $terms as $term )
{
PrintTerm( $term);
}
print "</ul>";
function PrintTerm( $term ) {
print "<li>";
print l($term->name, "taxonomy/term/$term->tid" ) ;
print "</li>";
$terms = taxonomy_get_children($term->tid );
if ( count( $terms ) > 0 ) {
print "<ul>";
foreach ( $terms as $term )
{
PrintTerm( $term);
}
print "</ul>";
}
}
?>
Bug in the code
I have been using the code provided above and it works fine. There is one bug although... The
$countvariable holds the total count of all nodes even if they are not published. This problem can be resolved by only counting the nodes which are published.I guess it can be done by performing a JOIN between
term_nodeandnodetables. Not sure though & I am not an SQL expert. Can someone please help by posting some code here.abhishan
abhishan
I used Taxonomy Menu module
I used Taxonomy Menu module and it works well.
Shalini Agarwal,
http://MegaLeecher.Net/
Deepesh,
http://MegaLeecher.Net/