Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
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
Comment | File | Size | Author |
---|---|---|---|
#25 | natural_seo3.png | 29.69 KB | naeluh |
#19 | natural_seo.png | 39.36 KB | naeluh |
Comments
Comment #1
DamienMcKennaTake a look at the APIs documented in nodewords.api.php, that'll be your best approach until the module is updated to use tokens.
Comment #2
naeluh CreditAttribution: naeluh commentedIs that available in the 6x.14? thanks when do you think tokens will be supported ?
Comment #3
naeluh CreditAttribution: naeluh commentedok yeah I think it would be this then that is getting the value from node
So maybe change it to my field of choice ?
Comment #4
DamienMcKennaThat's the one!
Comment #5
naeluh CreditAttribution: naeluh commentedAwesome thanks I will look a that for sure
Comment #6
naeluh CreditAttribution: naeluh commentedHi,
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
Comment #7
naeluh CreditAttribution: naeluh commentedComment #8
DamienMcKennaThere'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.:
Comment #9
naeluh CreditAttribution: naeluh commentedOk 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
Comment #10
DamienMcKennaOk, then try this:
Comment #11
naeluh CreditAttribution: naeluh commentedOh 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
Comment #12
naeluh CreditAttribution: naeluh commentedWeird - well that worked but I still could not output $parameters it was just
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
Comment #13
naeluh CreditAttribution: naeluh commentedCould 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
Comment #14
DamienMcKennaYou 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:
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.
Comment #15
naeluh CreditAttribution: naeluh commentedOk 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
Comment #16
naeluh CreditAttribution: naeluh commentedIs 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
Comment #17
naeluh CreditAttribution: naeluh commentedOk 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
Comment #18
naeluh CreditAttribution: naeluh commentedYeah I am a little stuck as to how the $parameters is referencing the node -
Maybe nodeapi to grab it ?
Comment #19
naeluh CreditAttribution: naeluh commentedMaybe 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
Comment #20
DamienMcKennaOk, 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.
Comment #21
naeluh CreditAttribution: naeluh commentedHi ,
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.
Comment #22
DamienMcKennaWhat is used to build each page that the nodes are loaded into? Panels? Views? Custom page-something.tpl.php files?
Comment #23
naeluh CreditAttribution: naeluh commentedIts custom node.tpl.php and page.tpl.php files
Comment #24
naeluh CreditAttribution: naeluh commentedHi
So I added this code into the module and returned the same result for $parameters
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
Comment #25
naeluh CreditAttribution: naeluh commentedOk really weird update for what ever reason this code
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.
Comment #26
naeluh CreditAttribution: naeluh commentedMaybe I could do something like this $id = ($nid); to pass the correct value to the nid to get the right field value ?
Comment #27
DamienMcKennaThis will be possible after #1380362: Re-implement Token integration lands.