By bettyatolive on
Hi,
I am getting the latest updated 3 nodes of content and displaying that in a block. So this is the code that I used for it.
$nlimit = 3;
$type = "story";
$result = db_query_range(db_prefix_tables("SELECT n.created, n.title, n.nid, n.changed
FROM {node} n
WHERE n.type = '$type'
ORDER BY n.changed
DESC "), 0, $nlimit);
while ($node = db_fetch_object($result)) {
$items[] =node_view(node_load(array('nid' => $node->nid)), 3);
}
if (isset($items) && is_array($items) && count($items) > 0)
{
echo "<ul>";
foreach ($items as $item)
{
echo "<li>" . $item . "</li>";
}
echo "</ul>";
}
This gives me a block which diplays the latest 3 story nodes with their teasers. Now I want to reduce the length of the teaser to 4-6 words. This should be done only for this block. Can somebody help me how to do that.
Thanks,
Betty
Comments
Have you considered using Views?
With views you can make all that:
Views then suggests you the templates (files ending in .tpl) that you can create in your current theme to override core's default look and feel.
I case you do that I would strongly suggest you use the Devel module to see how Views is passing the variables to your template.
What I generally do is that I use Views for trivial tasks like these then create my own PHP in template.php or a custom module for things Views cannot accomplish.
If you need help let me know.
-Alex
- Views module: http://drupal.org/project/views
- Devel module: http://drupal.org/project/devel
I agree. Views is the way to
I agree. Views is the way to go with this. You can use this installation profile http://drupal.org/project/openpublish to see a very good example of how to accomplish what you want using views. It's worth a couple hours time to pull it apart to see how it's done well. I used this installation profile as a base for my website.