Taxonomy terms are not getting added to keywords (+patch)
SteffenL - June 13, 2008 - 13:10
| Project: | Nodewords |
| Version: | 6.x-1.0-rc1 |
| Component: | Code |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Description
In Drupal 6, taxonomy_node_get_terms() no longer takes a node id as argument but a full $node object.
See http://drupal.org/node/114774#taxonomy-revisions
The following code in 6.x-1.0-rc1 keywords.inc is obviously incorrect and causes taxonomy terms to not generate keywords:
function nodewords_keywords_prepare($type, $ids, $value, $settings) {
if ($type == 'node' && function_exists('taxonomy_node_get_terms') && count($ids) == 1) {
if (node_access('view', node_load($ids[0]))) {
foreach (taxonomy_node_get_terms($ids[0]) as $term) {This should probably be something like:
function nodewords_keywords_prepare($type, $ids, $value, $settings) {
if ($type == 'node' && function_exists('taxonomy_node_get_terms') && count($ids) == 1) {
$n = node_load($ids[0]);
if (node_access('view', $n)) {
foreach (taxonomy_node_get_terms($n) as $term) {A patch that works for me is attached
Steffen

#1
I made this modification, and the taxonomy keyword feature is working so far.
#2
I've made the same modification, and the taxonomy keyword seems to work fine now. Included is a patch, as I don't see one attached to the ticket yet.
#3
The patch works well.
Just rerolled the pach ($n -> $node and some cleanup)
#4
there is one more problem, keywords looks like fun,humour,drupal but there should be space between them like fun, humour, drupal like that! any fix for it?
#5
okay i just fixed it with the help of a forum member
here is the code
<?php
// $Id: keywords.inc,v 1.1.4.3 2008/01/24 20:49:32 robrechtj Exp $
/**
* @file
* Support file for KEYWORDS meta tag.
*/
function nodewords_keywords_prepare($type, $ids, $value, $settings) {
if ($type == 'node' && function_exists('taxonomy_node_get_terms') && count($ids) == 1) {
$node = node_load($ids[0]);
if (node_access('view', $node)) {
foreach (taxonomy_node_get_terms($node) as $term) {
if (in_array($term->vid, $settings['keywords_vids'])) {
$value .= ', '. $term->name;
}
}
}
}
$value .= ', '. $settings['global']['keywords'];
$value = _nodewords_keywords_uniq($value);
return $value;
}
function nodewords_keywords_form($type, $value, $settings) {
return array(
'#type' => 'textfield',
'#title' => t('Keywords'),
'#default_value' => $value,
'#size' => 60,
'#maxlength' => $settings['max_size'],
'#description' => t('Enter a comma separated list of keywords for this page. Avoid duplication of words as this will lower your search engine ranking.'),
);
}
/*
* Uniq a string which is a seperated list to items, preserving
* the order in which they appeared.
*/
function _nodewords_keywords_uniq($text, $max_items = 0, $seperator = ', ') {
if (empty($text)) {
return $text;
}
$items = array_map('trim', explode($seperator, $text));
$uniq_values = array();
$uniq_lowers = array();
foreach ($items as $item) {
$lower = strtolower($item);
if (!in_array($lower, $uniq_lowers) && $lower != '') {
$uniq_values[] = $item;
$uniq_lowers[] = $lower;
}
}
if ($max_items > 0) {
$uniq_values = array_slice($uniq_values, 0, $max_items);
}
return implode($seperator, $uniq_values);
}
i just added space in three lines :D
#6
this patch (nodewords270193.patch) works great for me
#7
how do i apply this patch?
what do the + and - mean by each line?
#8
- means to removes those lines and + means to add those lines ;)
#9
the other option would be to copy the patch file to the module directory and from the command line type
patch < nodewords270193.patchthis should apply the patch
#10
lol i didnt knew that ^^ thanks ;)
#11
This patch works for me.
Thanks
#12
Patch works fine, awaiting inclusion into Nodewords proper.
#13
Thanks a lot
This patch works for me
What about including it into release?
If You have no time - I can do it (just add me to developers)
---------
Andriy Podanenko
web: http://my.ukrweb.info
#14
Hi Robert,
Will this patch go in D6 please?
Thanks a lot in advance for considering this!
Greetings.
Martijn
#15
Committed as part of http://drupal.org/node/340642.
Will be included in next releasE. Thanks!
#16
Automatically closed -- issue fixed for 2 weeks with no activity.