Posted by buffos on January 28, 2008 at 5:06pm
| Project: | RelatedContent |
| Version: | 5.x-1.6 |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | TBarregren |
| Status: | closed (fixed) |
Issue Summary
Now in the settings one can just choose to view Teasers or Full body.
It would be usefull to have an option to choose TITLES ONLY.
Comments
#1
Was going to post the same request, Titles only would be very useful, so +1
Thanks for all your work on this Module.
#2
remove user interface
#3
remove user interface
#4
remove user interface
#5
First of all, this feature will be include in next version of RelatedContent, which I expect to start working on in March.
For those who are in hurry, there is a quite easy way to accomplish this already today. Take a look at the API provided by RelatedContent.
Following pseudo code shows one way to accomplished this:
<?phpif (arg(0) == 'node' && is_numeric($nid = arg(1))) {
$nodes = relatedcontent($nid);
echo "<ul>\n";
foreach($nodes as $node) {
echo "<li>$node->$title</li>\n";
}
echo "</ul>\n";
}
?>
Following pseudo code is a more "elegant" way to accomplish the same thing:
<?php
if (arg(0) == 'node' && is_numeric($nid = arg(1))) {
$titles = relatedcontent($nid, 'title_of_node');
echo theme('titles', $titles);
}
function title_of_node($node) {
return $node->title;
}
function theme_titles($titles) {
$out .= "<ul>\n";
foreach($titles as $title) {
$out .= "<li>$title</li>\n"
}
$out .= "</ul>\n";
return $out;
}
?>
Please notice that the above code snippets are only pseudo code and hence will not work without further development.
The benefit with the later version, except from being more "elegant", is that
theme_titles()can be overridden in the template.php file, and make it, for instance, to read an titles.tpl.php file.It might seem strange that RelatedContent doesn't support titles already. It has a historical reason. I originally developed RelatedContent to be used in conjunction with Simplenews Template, also of mine, and Simplenews to assemble newsletter issues out of already existing nodes. Since this was done for a customer, it was initial developed to meet that particular customer's needs.
#6
More information is available in #218793.
#7
I needed to display only the body so I've developed the first pseudo code example above into working code;
<?php
if (arg(0) == 'node' && is_numeric($nid = arg(1))) {
$nodes = relatedcontent($nid);
foreach($nodes as $node) {
$nodeobject = $node[0];
echo $nodeobject->body;
/*echo "<pre>";
print_r($node);
echo "</pre>"; */
}
}
?>
For title replace echo $nodeobject->body with echo $nodeobject->title.
You don't need the commented out part (between /* and */), I left it in so you can see all the possible attributes that you can choose to display. Set the nodes per page or block to 1 in the view before uncommenting the commented code or you will get the details of every related node the view returns (you don't have to do this but you'll see why if you don't).
Hope this is useful, I need this feature and it's taken me a while to get this far.
#8
Just for the sake of demonstrating how the API of RelatedContent can be used to accomplish a block with links to related content, as seen in the attached image, I wrote following code snippet:
<?phpif (arg(0) == 'node' && is_numeric($nid = arg(1))) {
$host_node = node_load($nid);
$grouped = relatedcontent_variable_output_grouped($host_node->type);
if($groups = relatedcontent($host_node, $grouped)) {
foreach($groups as $group => $nodes) {
if ($nodes) {
$links = array();
foreach($nodes as $node) {
$links[] = l($node->title, "node/$node->nid");
}
$title = relatedcontent_group_title($group, $grouped, $host_node->type);
print theme('item_list', $links, $title);
}
}
}
}
?>
To use the code snippet, just cut'n'paste it into a block with PHP Input filter.
#9
Automatically closed -- issue fixed for two weeks with no activity.