Closed (fixed)
Project:
Term Fields
Version:
6.x-1.x-dev
Component:
User interface
Priority:
Minor
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
6 Jan 2010 at 16:40 UTC
Updated:
20 Mar 2012 at 08:56 UTC
Jump to comment: Most recent file
Comments
Comment #1
milo2man commentedI would also like to know this! I have created a custom taxomony_terms view using Views. I have used the following PHP snippet to display the term description in the header of each page and would like to add the custom term fields to the header as well.
I created a new term_field called "definition". Just trying to reference this with echo $current->definition doesn't work. How do I add this to the header?
If this method works, it would be possible to use the term fields with a nodes view, as well, via the page header.
Comment #2
rhache commented+1 for this.
I'd like to know how to fetch the term's field data on a node, without resorting to Views. Without going into details, I want to use term field on the node that would not work with views. I can fully illustrate a scenario if that would make a difference.
Some kind of load function, like node_load, would be great.
Rene
Comment #3
summit commented+1 also in need of showing term fields!
Greetings, Martijn
Comment #4
b-prod commentedThis patch add fields information in each terms present in $node->taxonomy. The fields are accessible in $node->taxonomy[XYZ]['fields'] where XYZ is the term tid.
It also add tokens for node, even for presave operation, so tokens may be used for pathauto replacements. It is supposed to handle tags vocabularies.
Before applying this patch, I want that some community users test it, especially with tokens and modules which use token replacements, like pathauto.
Thanks.
Comment #5
kthullPatch works beautifully with auto node titles. Thanks!
Comment #6
ryanilg commentedYou can also use any of the following functions included in the module. I just found these by looking at term_fields.module.
/**
* Retrieve a single field value given a term ID and field ID.
*/
function term_fields_get_field($tid, $fid) {
return db_result(db_query("SELECT %s FROM {term_fields_term} WHERE tid = %d", $fid, $tid));
}
/**
* Retrieve an array of fields from a given term, keyed by field ID.
*/
function term_fields_get_fields($term) {
if ($fids = term_fields_get_fids($term->vid)) {
$field_list = implode(',', $fids);
$sql = 'SELECT ' . $field_list . ' FROM {term_fields_term} WHERE tid = %d';
$result = db_query($sql, $term->tid);
return db_fetch_array($result);
}
return NULL;
}
/**
* Retrieve a term object like taxonomy_get_term(), but with fields.
*/
function term_fields_get_term($tid) {
$term = taxonomy_get_term($tid);
$fields = term_fields_get_fields($term);
$term->fields = $fields;
return $term;
}
Comment #7
b-prod commentedPorted in the dev version.
Comment #9
FamousNerd commentedIve created the page-taxonomy-term.tpl.php file and I'd like to pull the value of the field into the taxonomy page. When I try to the following code:
$term = term_fields_get_term(arg(2)); (where arg(2) is the integer id of my taxonomy term)
the error log shows PHP Fatal error: Call to undefined function term_fields_get_term()
Are these functions available from within template files?
Many thanks
Erik
Comment #10
b-prod commentedWhat version of the module do you use? The 2.x does no more use such function, since the data are attached directly to the node->taxonomy array.
This issue only concern 1.x version.
Comment #11
FamousNerd commentedGood point, I just checked and I'm on the following version: "6.x-2.0-alpha2"
Are you able to suggest to me the php syntax to retrieve values in the newer API version?
I should note, the page that I would like to show this on is a page display for a view. It's a list page and below that table which is the listing I want to show the taxonomy term's Field Value as "body text"
I'm not sure what this does for "$node", does that make it the taxonomy term's node? because $node->taxonomy seems empty.
Thanks
Erik
Comment #12
b-prod commented@FamousNerd: the $node->taxonomy is populated in node template files when viewing a node. So it does not apply to Views module displays which use "fields display". For that you have specific Views handlers.
I am not sure of what happen with node display, since I remember Views set node view modes ($a3, $a4) to 0. Moreover, the taxonomy term module uses hook_links() to alter the taxonomy array, so if you choose to not display the link, the taxonomy fields will be empty.
I hope it will help you to debug your issue. If you need some more help, could you please open a new issue against the 2.x version and describing your problem more accurately?