By stellarvisions on
Hey! I've gotten pretty far learning Drupal, but I admit I do not know PHP.
So, I found this fantastic snippet to make a block with links to taxonomy terms (which update the term is edited, which my users will do).
However, I need it to convert "Recent Paintings" to "recent-paintings" [term-raw] in the URL (leaving the term as is in the list). Is this something I should hire someone to do?
$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, "work/$term->name") . " ($count)";
}
if ( count($items) ) { print theme('item_list', $items);}
Comments
If I understand you
If I understand you correctly you want to change
to
hyphens not appearing
thanks for replying!
the lower case part works a treat, but I'm not getting the dashes. . .
also, it's changing the displayed text, I was hoping to be able to change only the link so the resulting HTML would be:
<a href="work/recent-paintings">Recent Paintings</a>This is because I'm linking to a URL alias for the term with the URL works/[term-raw] and I have token putting in dashes.
any help is greatly appreciated (or an estimate of cost to solve it?) - -
ideally, I'd also like menu-like behavior where the current term has a different class. . . :)
best,
---
Stella Gassaway
principal
STELLARViSIONs : communication architects
http://www.stellarvisions.com
We design culture-driven tools™
that shape how information is
organized, displayed, shared, and
experienced to reflect core values.
---
Stella Gassaway
principal
stellarvisions : communication architects
http://www.stellarvisions.com
We design culture-driven tools™
that shape how information is
organized, displayed, shared, and
experienced.
See the correction above, I
See the correction above, I replaced "work/$term->name" with "work/$name".
As for a different class for the "active" term you would need to define what active term means
WORKS!
wonderful. awesome.
thanks very much for the speedy help -- it removes a huge roadblock for me.
---
Stella Gassaway
principal
STELLARViSIONs : communication architects
http://www.stellarvisions.com
We design culture-driven tools™
that shape how information is
organized, displayed, shared, and
experienced to reflect core values.
---
Stella Gassaway
principal
stellarvisions : communication architects
http://www.stellarvisions.com
We design culture-driven tools™
that shape how information is
organized, displayed, shared, and
experienced.
update - I spoke too soon.
I'm obviously doing something wrong because I investigated more carefully and it seems that I'm just not getting it to work at all (even the lower case part), let me work on it a bit -- maybe I'm missing something obvious. . .
---
Stella Gassaway
principal
STELLARViSIONs : communication architects
http://www.stellarvisions.com
We design culture-driven tools™
that shape how information is
organized, displayed, shared, and
experienced to reflect core values.
---
Stella Gassaway
principal
stellarvisions : communication architects
http://www.stellarvisions.com
We design culture-driven tools™
that shape how information is
organized, displayed, shared, and
experienced.
ignore "spoke too soon" all is well.
---
Stella Gassaway
principal
STELLARViSIONs : communication architects
http://www.stellarvisions.com
We design culture-driven tools™
that shape how information is
organized, displayed, shared, and
experienced to reflect core values.
---
Stella Gassaway
principal
stellarvisions : communication architects
http://www.stellarvisions.com
We design culture-driven tools™
that shape how information is
organized, displayed, shared, and
experienced.
Works for me too.
Thanks! I've been trying to change the default taxonomy link, and this finally does it.
I made nevets' changes to stellarvision's code, then combined it with another version that doesn't show the count numbers, but hides terms with no content. I might have some extra stuff in there but it seems to work for me:
Adding the item count to each term name
This is a very helpful code snippet, but how would I add the item count for term in parenthesis next to the term's name? Any suggestions would be greatly appreciated!
Change $items[] =
Change
to
if you want the count part of the link or
if you don't want the count as part of the link.
Sorting Alphabetically
Thank you very much for this code, it worked great for me.
Some people may run into a situation like I had in which they need to order their terms Alphabetically. This is complicated a bit because the sort() function and the asort() function can't grab data from the 'term' objects in this 'terms' array. The answer lies in php's usort function, which I'd never used until now, but did the trick immediately.
Somewhere in the page's PHP put the following function:
Then, right before you begin looping through the terms (
foreach ( $terms as $term ) {in stellarvisions code ) call the function with the code:More information on usort is at http://us2.php.net/usort
Note this is only needed if
Note this is only needed if your terms are not using the default order (which is alphabetical) and you want them in alphabetical order.