I want to grab the text from a field other than the body field or node teaser for the node meta description - is there a way to do this? I saw that there was an option for regular expression is there a way to handle it with this. Basically in the system I am working with the body has been omitted from the node.

Let me know if I can provide any other info that would be helpful

thanks

CommentFileSizeAuthor
#25 natural_seo3.png29.69 KBnaeluh
#19 natural_seo.png39.36 KBnaeluh
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

DamienMcKenna’s picture

Status: Active » Fixed

Take a look at the APIs documented in nodewords.api.php, that'll be your best approach until the module is updated to use tokens.

naeluh’s picture

Is that available in the 6x.14? thanks when do you think tokens will be supported ?

naeluh’s picture

ok yeah I think it would be this then that is getting the value from node

function hook_nodewords_tags_alter(&$output, $parameters) {
  if (empty($output['abstract']) && $parameters['type'] == NODEWORDS_TYPE_PAGE) {
    $output['abstract'] = t('Node content');
  }
}

So maybe change it to my field of choice ?

DamienMcKenna’s picture

Version: 6.x-1.4 » 6.x-1.14

That's the one!

naeluh’s picture

Awesome thanks I will look a that for sure

naeluh’s picture

Hi,

So Im used the devel module to find my field

My code below does not seem to be working

Would I have to obtain the nid in another function before I can grab out the field value ?

thanks


function hook_nodewords_tags_alter(&$output, $parameters) {
  if (empty($output['abstract']) && $parameters['type'] == NODEWORDS_TYPE_PAGE) {
    $output['abstract'] = $node->field_content_header[0]['safe_value'];
  }
}
naeluh’s picture

Status: Fixed » Active
DamienMcKenna’s picture

There's a very simple mistake - you are trying to get values off the variable $node, but that variable doesn't exist within the function. What you should do is use Devel module's dpm() function to find out what the $parameters are and then decide how to proceed, e.g.:

function mymodule_nodewords_tags_alter(&$output, $parameters) {
  if (empty($output['abstract']) && $parameters['type'] == NODEWORDS_TYPE_PAGE) {
    dpm($parameters);
  }
}
naeluh’s picture

Ok cool so I added that and in the output I didn't any $parameters out put on the page could it be possible that there are not any available the way my field are set up ?

thanks

DamienMcKenna’s picture

Ok, then try this:

function mymodule_nodewords_tags_alter(&$output, $parameters) {
  dpm($parameters);
}
naeluh’s picture

Oh you know what I just noticed that this was for a new module - Let me try and create a module and see if I can get it to work then I was just calling it directly in the nodewords.api.php I will create a new module and see if I can get it show the $parameter tree thanks

naeluh’s picture

Weird - well that worked but I still could not output $parameters it was just

... (Array, 4 elements)
type (Integer) 10
id (Integer) 0
default (Array, 10 elements)
abstract (Array, 1 element)
copyright (Array, 1 element)
dcterms.contributor (Array, 1 element)
dcterms.creator (Array, 1 element)
dcterms.publisher (Array, 1 element)
description (Array, 1 element)
keywords (Array, 1 element)
location (Array, 2 elements)
revisit-after (Array, 1 element)
robots (Array, 1 element)
output (String, 4 characters ) head
<?php
function nodewords_default_nodewords_tags_alter(&$output, $parameters) {
  if (empty($output['abstract']) && $parameters['type'] == NODEWORDS_TYPE_PAGE) {
    dpm($parameters);
  }
}

This was already available in the in the tree that devel pumped out originally - Am I supposed to assign the the $node field array to the description array Cause it doesnt look like anything is available in parameters

thanks again for all your help

naeluh’s picture

function nodewords_default_node_load($param = array(), $revision = NULL, $reset = NULL){
$node=node_load(arg(1));
if($node) {
return $node->field_content_header[0]['nid'];
} 
else {
return FALSE;
}
}


function nodewords_default_nodewords_tags_alter(&$output, $parameters) {
  if (empty($output['abstract']) && $parameters['type'] == NODEWORDS_TYPE_PAGE) {
    $output['abstract'] = $node->field_content_header[0]['safe_value'];
  }
}

Could I do something like this ? I did but it didnt work - I was trying to load the current node and pass the value to the description but maybe I am doing this completely wrong

DamienMcKenna’s picture

You are doing it a little incorrectly :)

What you need to do is create your own module. I recommend starting the module's name after your site rather than Nodewords, to avoid confusion later on, so e.g. "example_seo" to bundle all SEO changes for example.com. Put those together, you'd be creating the "example_seo" module with its own example_seo.info and example_seo.module files, then in the .module file add this:

/**
 * Implements hook_nodewords_tags_alter().
 */
function example_seo_nodewords_tags_alter(&$output, $parameters) {
  if (empty($output['abstract']) && $parameters['type'] == NODEWORDS_TYPE_PAGE) {
    dpm($parameters);
  }
}

When Nodewords runs it still does not see the $node variable inside the mymodule_nodewords_tags_alter() function until you create it - adding a separate mymodule_node_load() function makes absolutely no difference to variables are available inside mymodule_nodewords_tags_alter.

The reason I was suggesting doing dpm($parameters) was to find out how to reference the node inside of the $parameters array, and using dpm() can help. Once you find out how to reference the node, you can then add the ->field_content_header[0]['safe_value']; part, but you need to start with the node. Also, add another if() statement around it to check in case field_content_header[0]['safe_value']; is empty.

Feel free to post more code and I can guide you further.

I also suggest reading some tutorials on PHP programming and practicing some more to help you become more comfortable with functions and variables (especially arrays), it'll greatly help your ability to understand Drupal and customize it for your sites.

naeluh’s picture

Ok yeah I see that there's nid which is the exact node and then there is type which is the content type which shows up in both so I think if I can reference the type I will be able to get the field value

Yeah I really want to learn for sure I will check it out for sure I will check out some more array code and also I am learning oop php which seems like its really strait forward once you get the hang of it.

So I think if I can reference the node type I will be able to get the field info.

I am going to try a couple of thing and then report back here

thanks again for all your help

naeluh’s picture

Is that the right logic since they both reference type then they share that value or are those both different types?
Also here is what I got so far

function natural_seo_nodewords_tags_alter(&$output, $parameters) {
  if($node->field_content_header[0]['value'] != NULL);
  if (empty($output['abstract']) && $parameters['type'] == NODEWORDS_TYPE_PAGE) {
    dpm($parameters);
  }
  
}
naeluh’s picture

Ok so the line I put in is throwing these errors -

Notice: Undefined variable: node in natural_seo_nodewords_tags_alter() (line 3 of /srv/bindings/85aea319acc545159bc35a0f87db6d33/code/sites/all/modules/natural_seo/natural_seo.module).
Notice: Trying to get property of non-object in natural_seo_nodewords_tags_alter() (line 3 of /srv/bindings/85aea319acc545159bc35a0f87db6d33/code/sites/all/modules/natural_seo/natural_seo.module).

I am guessing because it is because it has no value

naeluh’s picture

Yeah I am a little stuck as to how the $parameters is referencing the node -

Maybe nodeapi to grab it ?

naeluh’s picture

FileSize
39.36 KB

Maybe if you could explain a little better because I don't see anything that would really be helpful in this data tree -

Here's a screen shot attached to this post

I am just not sure what to reference to get the node and then the field

thanks

DamienMcKenna’s picture

Ok, so one thing to note from the screenshot is that when the 'type' value is 10 then it's loading a page that is specifically not a node page - if the module was recognizing it as a node page then it would be 5 instead. What are you using to edit that page?

You might also want to change to using hook_nodewords_tags_output_alter() as that lets you adjust all of the meta tags after Nodewords has finished processing them.

The reason that the code in comment #16 gives that error is that again there is no $node variable. Just to clear up any assumptions you have, the variable "$node" doesn't mean anything until you assign data to it. Also, because you use the arrow notation on the variable you're telling PHP that the $node variable is to be treated as a object rather than a simpler variable like a string or an array. Furthermore, while there are certain naming conventions used within Drupal, just naming a variable a certain way, e.g. "$node", doesn't work any magic to cause it to become something specific, e.g. a node object, your code has to do the work to make it contain the data you expect it to have. So, when you say "$node->field_content_header" in your code you're telling PHP that you want to work with the field_content_header attribute of the $node object that was defined earlier, but in your code you're not defining the $node variable, so it doesn't exist, so you can't access the field_content_header value.

The reason I was suggesting to display the $parameters was to find out if one of the values in that array was the node object or maybe even the node ID, which could be used to load the node.

naeluh’s picture

Hi ,

ok I kinda of suspected that myself about the calling $node when there is no value because there isnt any data to pull from I understand that for sure why I am getting the undefined variable

I think there is kinda of a weird setup for the d6 install that I have where there are multiple content types showing on one page or rather multiple nodes on a page. that might have something to do with the 10 types. I have really never seen drupal implemented this way so I might have my hands this is why I am in this position because the body field has been omitted from all the content type forms also.

Anyway I will try the other hook and see what results I can get. I will see if this gives me better variables.

I am on a node page I just there might be an issue because there are multiple nodes on the page well see...

and once again thanks for your help.

DamienMcKenna’s picture

What is used to build each page that the nodes are loaded into? Panels? Views? Custom page-something.tpl.php files?

naeluh’s picture

Its custom node.tpl.php and page.tpl.php files

naeluh’s picture

Hi

So I added this code into the module and returned the same result for $parameters

function natural_seo_nodewords_tags_output_alter(&$output, $parameters) {
  $bool = (
    variable_get('nodewords_add_dc_schema', FALSE) &&
    isset($parameters['output']) &&
    $parameters['output'] == 'head'
    
  );
  
  dpm($parameters);

  if ($bool) {
    $output = (
      '<link rel="schema.dc" href="http://purl.org/dc/elements/1.1/" />' . "\n" .
      $output
    );
  }
}

It was the 10 types again. I just wanted to see if I understand this function - its a boolean that has already created the values from nodewords and has put them in the head of the page. Can I now alter the default items to get the value from the field i want ?

Or would I do this before this function has run? Also I am still not sure how to get the field since I am still returning the same $parameters. I feel as though I need to somehow get the nid I want to return an array of all the fields and then pass that to the new module I have created to pullout the correct set it to the description. Is that correct or am I way off base ?

thanks

naeluh’s picture

FileSize
29.69 KB

Ok really weird update for what ever reason this code

function natural_seo_nodewords_tags_output_alter(&$output, $parameters) {
  $bool = (
    variable_get('nodewords_add_dc_schema', FALSE) &&
    isset($parameters['output']) &&
    $parameters['output'] == 'head'
    
  );
  
  dpm($parameters);

  if ($bool) {
    $output = (
      '<link rel="schema.dc" href="http://purl.org/dc/elements/1.1/" />' . "\n" .
      $output
    );
    
    
    
  }
}

is now producing a 5 types now and I didn't change anything - so some how that problem got fixed haha

Here is what the output looks like now I attached a png

So I think now if I can alter the nodewords output post processing to add in my field value I think it should work I guess I see that it has the id of 3555 and that is the nid also 3555 so there is a reference to each other there. So somehow I need to capitalize on that I think so maybe get the $id (* ids - the array of IDs for the object associated with the page.) from nodewords and then I will have the field value I am looking for I think.

naeluh’s picture

Maybe I could do something like this $id = ($nid); to pass the correct value to the nid to get the right field value ?

DamienMcKenna’s picture

Version: 6.x-1.14 » 6.x-1.x-dev
Issue summary: View changes
Status: Active » Closed (duplicate)

This will be possible after #1380362: Re-implement Token integration lands.