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

Comments

Rob T’s picture

I made this modification, and the taxonomy keyword feature is working so far.

jcfiala’s picture

Status: Active » Needs review
StatusFileSize
new980 bytes

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.

vladimir.dolgopolov’s picture

StatusFileSize
new969 bytes

The patch works well.
Just rerolled the pach ($n -> $node and some cleanup)

Arshad Vayani’s picture

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?

Arshad Vayani’s picture

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

jrglasgow’s picture

Status: Needs review » Reviewed & tested by the community

this patch (nodewords270193.patch) works great for me

netentropy’s picture

how do i apply this patch?

what do the + and - mean by each line?

Arshad Vayani’s picture

- means to removes those lines and + means to add those lines ;)

jrglasgow’s picture

the other option would be to copy the patch file to the module directory and from the command line type

patch < nodewords270193.patch	

this should apply the patch

Arshad Vayani’s picture

lol i didnt knew that ^^ thanks ;)

marcob’s picture

This patch works for me.
Thanks

wildtang3nt’s picture

Patch works fine, awaiting inclusion into Nodewords proper.

podarok’s picture

Category: bug » support

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

summit’s picture

Hi Robert,

Will this patch go in D6 please?
Thanks a lot in advance for considering this!

Greetings.
Martijn

Robrecht Jacques’s picture

Status: Reviewed & tested by the community » Fixed

Committed as part of http://drupal.org/node/340642.

Will be included in next releasE. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

shaneonabike’s picture

Version: 6.x-1.0-rc1 » 6.x-1.12-beta9
Status: Closed (fixed) » Active
Issue tags: +taxonomy, +Nodewords, +tags, +term, +custom page

Strange. It seems like there is actually a problem again in the latest release. In debugging the code custom pages are actually generating the proper keywords associated with a node but they aren't actually being output. I tried to look through the code but can't seem to figure out what is wrong....

Ideas? I could really use this functionality and would be willing to help contribute I'm getting a bit confused with the difference of obtaining the keywords and rendering in the nodewords code.

shaneonabike’s picture

Actually I noticed that the keywords don't actually 'automagically' add themselves to each node. But rather if you add the [metatags-taxonomy-keywords] token to each custom page keyword section then they do add themselves properly. Is that the intended behavior?

Anonymous’s picture

Status: Active » Fixed

Is that the intended behavior?

Yes, it is.

shaneonabike’s picture

Okay that's totally cool but maybe change the wording of the Defaults page from:

Select the vocabularies which contain terms you want to add to the keywords meta tag for nodes.

to:

Select the vocabularies which contain terms you want to add to the keywords meta tag for nodes. These are placed in [metatags-taxonomy-keywords] token which should be added to your keywords section.
Anonymous’s picture

I changed the description to Select the vocabularies which contain terms you want to add to the content of the token metatags-taxonomy-keywords.

Status: Fixed » Closed (fixed)
Issue tags: -taxonomy, -Nodewords, -tags, -term, -custom page

Automatically closed -- issue fixed for 2 weeks with no activity.