Επειδή στο theme τα Taxonomy Terms ενός node τα εμφανίζει όλα μαζί, και μερικές φορές δεν είναι πολύ λειτουργικό, καθώς μπερδεύονται τα terms από διαφορετικά Vocabulary, χρειάζεται να τα ξεχωρίσεις ώστε να εμφανίζονται ανα Vocabulary.
Αυτό ίσχυε και στο mydrupal.gr οπού τα Terms από τα Vocabulary Forum, Drupal version, modules, tags εμφανιζόντουσαν όλα μαζί.
Για να τα ομαδοποιήσουμε σύμφωνα με το Vocabulary χρειάζεται να φτιάξουμε μια function στο template.php του theme που χρησιμοποιούμε και να την καλέσουμε στο node.tpl.php
Στο template.php προσθέστε
<?php
function mytheme_print_terms($nid) {
$vocabularies = taxonomy_get_vocabularies();
$output = '';
foreach($vocabularies as $vocabulary) {
if ($vocabularies) {
$terms = taxonomy_node_get_terms_by_vocabulary($nid, $vocabulary->vid);
if ($terms) {
$links = array();
$output .= 'vid . '">';
$output .= ' ' . $vocabulary->name . ': ';
foreach ($terms as $term) {
$links[] = l($term->name, taxonomy_term_path($term), array('rel' => 'tag', 'title' => strip_tags($term->description)));
}
$output .= implode(', ', $links);
$output .= ' ';
}
}
}
$output .= '';
return $output;
}
?>
Στο node.tpl.php
Αφαιρέστε τον κώδικα ή ακόμα καλύτερα βάλτε τον σε comment που αναφέρετε στο print $terms και προσθέστε <?php print mytheme_print_terms($node->nid) ?>
Π.χ.
<?php if ($links): ?>
<?php endif; ?>
ΠΡΟΣΟΧΗ όπου mytheme βάλτε το όνομα από το θέμα που χρησιμοποιείτε. Δηλαδή άμα χρησιμοποιείτε το garland theme το function mytheme_print_terms($nid) θα γίνει function galrand_print_terms($nid)
Ανά Vocabulary μπαίνουν σε ένα span με class = vocabulary id ώστε μετέπειτα να μπορούν να γίνουν και theming μεσώ css ;)
Μπράβο Νεκτάριε για το tip!
thanx!
Για να εκτυπώσουμε στο node.tpl.php μόνο τα terms ένος συγκεκριμένου vocabulary μπορούμε να χρησιμοποιήσουμε την παρακάτω fuction αφου την βάλουμε στο αρχείο template.php
<?php function mytheme_print_only_terms_of($nid, $vid) {
$terms = taxonomy_node_get_terms_by_vocabulary($nid, $vid);
if ($terms) {
$links = array();
$output .= '';
foreach ($terms as $term) {
$links[] = l($term->name, taxonomy_term_path($term), array('rel' => 'tag', 'title' => strip_tags($term->description)));
}
$output .= implode(', ', $links);
$output .= ' ';
}
$output .= '';
return $output;
}?>
Και μετά μπορούμε να την εκτυπώσουμε μέσα στο το node.tpl.php αρκεί να ξέρουμε το vid του vocabulary Πχ αν το vocabulary main category έχει vid 3 τότε γράφουμε:
<?php print mytheme_print_only_terms_of($node->nid, 3 ); ?>
Ωραίο το παράδειγμα σου . . .
Βασικά κάτι σχετικό με τα terms αν μπορώ να ρωτήσω . . .
Σε περίπτωση που θέλω δίπλα απο τα terms αν τα έχω επιλέξει σε μορφή tags κατα το create content πώς μπορεί να βλέπω παράλληλα και το term->name αλλά και to term->description . . .
δλδ κατά το auto_complete του πεδίου της φόρμας αν πληκτρολογώ
Κωδικοί
343434->Πάγια Έξοδα
343435->Πάγια Έξοδα Γραφείου
343435->Πάγια Έξοδα Οχημάτων
κτλ.
Φαντάζομαι ότι μέσα απο το module της taxonomy θα χρειάζεται να προσθετεί το κατάλληλο πεδίο στην κλήση απο το query και να εμφανιστεί μετά αλλά που το βρίσκω μέσα στον κώδικα είναι το πρόβλημα μου?
Ευχαριστώ.
4.6 – 5
taxonomy_node_get_terms_by_vocabulary($nid, $vid, $key = 'tid')
6
taxonomy_node_get_terms_by_vocabulary($node, $vid, $key = 'tid')
Πολύ καλό το post, απλά για όποιον ενδιαφέρεται για drupal 6
/**
* GT
* Returns the terms of a specific vocabulary.
* Paremeters: Node id, Vocabulary id
*
*/
function yourthemename_print_only_terms_of($node, $vid) {
$terms = taxonomy_node_get_terms_by_vocabulary($node, $vid);
if ($terms) {
$links = array();
$output .= '';
foreach ($terms as $term) {
$links[] = l($term->name, taxonomy_term_path($term), array('rel' => 'tag', 'title' => strip_tags($term->description)));
}
$output .= implode(', ', $links);
$output .= ' ';
}
$output .= '';
return $output;
}
και η κλήση από οποιοδήποτε node-[type].tpl.php
<?php print yourthemename_print_only_terms_of($node, 2 ); ?>
4.6 – 5
taxonomy_node_get_terms_by_vocabulary($nid, $vid, $key = 'tid')
6
taxonomy_node_get_terms_by_vocabulary($node, $vid, $key = 'tid')
Πολύ καλό το post, απλά για όποιον ενδιαφέρεται για drupal 6
/**
* GT
* Returns the terms of a specific vocabulary.
* Paremeters: Node, Vocabulary id
*
*/
function yourthemename_print_only_terms_of($node, $vid) {
$terms = taxonomy_node_get_terms_by_vocabulary($node, $vid);
if ($terms) {
$links = array();
$output .= '';
foreach ($terms as $term) {
$links[] = l($term->name, taxonomy_term_path($term), array('rel' => 'tag', 'title' => strip_tags($term->description)));
}
$output .= implode(', ', $links);
$output .= ' ';
}
$output .= '';
return $output;
}
και η κλήση από οποιοδήποτε node-[type].tpl.php
<?php print yourthemename_print_only_terms_of($node, 2 ); ?>