How to get a excerpt content of a node? - drupal

I am having a node reference.How can i get its excerpt content?
For getting title or body we use:-
print $entry->title;
print $entry->body;
How i can get the excerpt of that node.(i am using excerpt module)

For the stock teaser, it would be $entry->teaser but your best bet is to use
drupal_set_message(print_r($entry, true))
and look through the key=>value pairs.
For a better looking array, install the Devel module and use
dsm($entry)

The teaser of a node is contained in $entry->teaser; if the field is not initialized, then the function node_teaser() is the function used to build the teaser.
If the module is saving a custom value as excerpt, you should verify which is the property used from the module (I would check $entry->excerpt, though).
I would suggest you to install Devel, which has some debug functions, including dsm() that allows to inspect any PHP value, and also adds a tab "Devel" for each node.

Can you var_dump $entry? Does it have more data?

Related

Drupal 6 Views 2 using Node Path as an argument

Please consider helping a Drupal noob who is in danger of tearing out what hair I have remaining.
I have a view that I want to add an argument to so that it only displays the details of the specified product. Since I'm using URL aliasing the argument is in the form of shop/product1, shop/product2 etc. However, when I go to add an argument node path (which is what I have set to shop/product1 etc is not listed) the only I could use is Node: Nid but that doesn't work because my argument is not a node id but a path alias.
The workaround I've been using is to create a CCK field to store my node path and then create an argument using the CCK field. Is this the only option?
Regards,
Sean
One way to do this would be to create a custom module and define your own callback which would then work out the NID from the path and pass that as an argument to the view using views_embed_view.
There are some contrib modules which allow you to filter by PHP code which would probably do as well.
I believe you can still use NID as the argument, as that is what's in the actual path even though you are displaying an alias in the address bar.

Custom formatter

I need to create a new custom formatter(using the module custom formatter) to replace some template code. So, for some fields, When I add a new custom formatter(field type: text) I need to print the title and the body. I tried to use $node->title but it doesn't work...
How can I do this? Probably using elements? And if yes...how?
Thanks in advance,
Regards,
Michele
Field formatters relate to the field that they are used for, it it's impossible to answer your question without know what field you are using (and it's contents).
To debug this, you could use the devel module and a bit of code. If you in your formatter write.
dpm(get_defined_vars());
this will give you a pretty printed list of all variables you have available. That should help you inspect and figure out how you get to what you need.
Custom formatters get's passed $element, if you do a dpm of $element (dpm($element) - If you have the Devel module installed) you will see the entire array, and notive that the $node object is passed as $element['#node'].
So with that said, to get to the node title you would use $element['#node']->title.
Please also not that it does say this on the help text of the custom formatters UI.

Drupal 6: getting particular fields from Node Reference types

I'm a drupal newbie...
<?php print $node->field_date[0]['view']; ?>
I can get the custom created CCK fields' value and display in tpl.php files as above... that's fine.
my question is how can I get the Node reference fields' in-fields? for example, I have an event content type, and I have defined Node Reference for Location (title, address, img, etc.). When I write the code below, it displays all location content;
<?php print $node->field_location[0]['view']; ?>
but I need to get only address field from this location content type. sth like below would be great :D but not working;
<?php print $node->field_location[0]['field_address']['view']; ?>
so how can get that? appreciate helps so much! thanks a lot!
You should inspect/dump the content of the $node->field_location array. I do not have a test installation at hand right now, so I can't say for sure, but I'd expect that at least the referenced nodes id ('nid') should be in that array somewhere. With that, you can do a node_load($nid), which returns the full node object, thus providing access to the fields.
(As said, I'm not sure, but the field array might already contain the whole node object as well, saving you from the need to load it explicitely.)
The $node->field_location[0]['view']; returns the node as it was defined in the Display Fields section of the content type definition. This might work for your advantage. You can trick it: use a Teaser display for that node and customize the node Teaser display to fit your needs. Just a thought.
If that doesn’t work for you, you will need to load the node separately. You can use $node->field_location[0]['nid']; to get the node ID, so you will end up with something like this:
node_load($node->field_location[0]['nid'])->field_address[0]['view']
I'm not sure how this performs...

Where in code do I add taxonomy_save_vocabulary for drupal module

I know that in order to programmatically add my own taxonomy to a node I need to use the taxonomy_save_vocabulary function and pass it an array defining my vocabulary. But I need to know where does this code usually go in the module. I'm assuming the install file?
Thanks!
D
The install file is for initial set up of your module - setting up database tables and clearing up for uninstall, basically. So yes, if you're adding a taxonomy just once, and especially if it's indispensible to your module, this would be a good place to do it.
More ideas about this here:
http://sachachua.com/wp/2009/04/drupal-staging-and-deployment-tips-its-all-code/

Drupal Views (Page) Using Human-Friendly Path

I have CCK and Views module installed. For the sake of this question scope, I'll call the content type as Project. Projects have many Members.
Project nodes are accessible through /project/project-name. I want to be able to display list of members through path /project/project-name/members.
Is there any way to do this?
Currently I have a views setup for page display on path /project/%/members, and have the argument taken from the url. I realize I can't use "Node ID from URL" option directly since it's node name instead of node id. Therefore I tried to enable "PHP Code" argument. But the problem is, Drupal Views always assume that the parameter is "project-name" and therefore ignored my php code argument setting. Anyone knows how I might be able to do this?
Thanks
Yes, you can actually use the "Node ID from URL" option, and you should.
Use the path or pathauto module to generate human-readable URLs for your projects in the form project/project-name. This will create a human-readable alias for the node, but the underlying Drupal system path is still node/nid.
Views can still use the "Node ID from URL" as an argument (or Contextual filter, as they are known in Drupal 7) even with human-readable aliases for those ugly paths.
If the project's name is the node title you can get what you want pretty easily.
You can pass the node title as argument instead of the nid, but the result will be the same. You get some options to use lowercase, transform - to space ect, as what you can do in a url is limited compared to a node title.
The rest of the view would be the same, as the solution using node nids in the url.
You need to create path aliases for /project/project-NID/members to /project/project-Name/members
I asked this exact question a month ago. :)
drupal link to view dependent on argument

Resources