Remove title, timestamp and author from related content
j0hn-smith - February 7, 2008 - 05:20
| Project: | RelatedContent |
| Version: | 5.x-1.6 |
| Component: | Miscellaneous |
| Category: | support request |
| Priority: | normal |
| Assigned: | TBarregren |
| Status: | closed |
Jump to:
Description
relatedContent is excellent, well done.
How can I only display the body of the related node instead of the full node?
In relatedcontent.tpl.php I've tried adding
print_r($content);
after
echo content;
but it gives me the whole node again. I don't know enough php or Drupal to go any further.
Thanks

#1
I found issue #215123: Title only listing of related nodes in settings where you suggest some sudo code, I'll try that with with $body instead of $title.
#2
Yes, the pseudo code in #215123 is a good starting point to accomplish what you want. I included a small but powerful API in RelatedContent just for that purpose. The interesting function is
<?phprelatedcontent($node, $output_grouped, $content_function, $content_function_args)
?>
As described in the modules handbook,
relatedcontent()returns an array whose keys are the names by which the output should be grouped according to$output_grouped, i.e. names of content types, authors, views or'all', and whose values are also arrays of the return values of calling$content_functionwith the node objects with related content of$nodeas the first argument and$content_function_argsas the following arguments.For an example, calling
<?phprelatedcontent($node, 'type', 'my_function', array($arg_1, $arg_2));
?>
returns something similar to this:
<?phparray(
'story' => array(
[0] => my_fynction($nodes[4], $arg_1, $arg2),
[1] => my_fynction($nodes[12], $arg_1, $arg2),
...
[m] => my_fynction($nodes[67], $arg_1, $arg2),
),
'page' => array(
[0] => my_fynction($nodes[1], $arg_1, $arg2),
[1] => my_fynction($nodes[45], $arg_1, $arg2),
...
[n] => my_fynction($nodes[78], $arg_1, $arg2),
)
?>
where
$nodes[#]is the node object next in turn, according to its source view's sort order, whithin its group.The only argument that is mandatory is $node, which is the node id or node object of the node whose related content is to be returned. The default value of
$output_groupedisfalse, which results in a single group called'all'. The default value of$content_functionis a function that merely returns the node object itself. The default value of$content_function_argsis en empty array, i.e. no arguments.If you are not using the API, but just rely on the default behavior of the module, that corresponds to following call:
<?phprelatedcontent($node, $output_grouped, 'node_view', array($output_teasers))
?>
where
$output_groupedand$output_teasersis set according to the settings of the content type of the node given by$node. The functionnode_view()used as the content function, is Drupal's standard function for generating the display of a node as either a full page or a teaser.The fact that RelatedContent uses
node_view()as it content function implies that the styling of the bodies or teasers of the related content themselves must be done through the regular theming of nodes, i.e. by overridingtheme_node()or changes innode.tpl.phpfile.The documentation of the function in source code documentation of
relatedcontent()gives some examples of how it can be used. See also the documentation.#3
Wow, thanks for replying so fast.
I know that the API can be used to achieve what I want but even though your code is commented perfectly in the module source code, my programming skills aren't sufficient to understand anything but step by step examples, eventually I get there by trial and error. I must learn about using API's.
For others needing similar functionality here's a copy of my post with working code originally posted here #215123: Title only listing of related nodes in settings (apologies duplicating the issue).
#4
I have expanded your example in this comment http://drupal.org/node/215123#comment-720582.
#5
Automatically closed -- issue fixed for two weeks with no activity.