By Anonymous (not verified) on
Hi !
I have this code somebody gave me a long time ago to display the X last nodes - 1. It means it should display for eg. the last 5 teasers of the last 5 published nodes except the very last one wich will be displayed somewhere else on the website.
It could be cool but the code doesn't work in my Drupal 4.7.
Can somebody help me please ?
Thanks a lot ;)
<?php
/**
* This php snippet displays content of a specified type, with teasers,
* from certain taxonomy term.
* Sorted by date of creation, most recent first.
* Works with nodes of the flexinode type too.
* To change the length of the list, change $listlength.
* To change the taxomony term, change $taxo_id.
* To change the type of content listed, change the $content_type.
* Tested with Drupal 4.6.3
*/
$listlength="5";
$taxo_id = 1;
$content_type = 'story';
$count = 0;
$result1 = pager_query(db_rewrite_sql("SELECT n.nid, n.created FROM {node} n INNER JOIN term_node ON n.nid = term_node.nid WHERE n.type = '$content_type' AND term_node.tid = $taxo_id AND n.status = 1 ORDER BY n.created DESC"), $listlength);
while ($node = db_fetch_object($result1)) {
if($count > 0)
{
$output .= node_view(node_load(array('nid' => $node->nid)), 1);
}
}
print $output;
?>
Comments
In fact it means...
In fact it means that I want to display the LAST BUT ONE NODES ;)
Maybe it's clearer. I really need your help ;)
Here is one way
While you could make a simplier change (there is no incrementing of $count) I also updated the snippet to be more "Drupalized". I also change pager_query to db_query_range which is the more approriate function and added the ability to specify how many records to skip. Also $liistlength is now the number of nodes to display. The call to node_load() was updated to use the simplier interface when the only thing passed is the nid.
On my windows box,
n.type = '%s'needs to be coded asn.type LIKE '%%%s%%'to work.You did a really great job !
Hi Nevets,
You did a really great job !
I'm sure it will help every Drupal user who wants to have a kind a Newspaper layout.
Thanks a lot, it works perfectly :)
Matt
Big problem: teasers displayed twice
HI!
I've a problem with this code.
For some reasons, I've edited my flexinodes and suddely, each teaser's displayed twice on my page...
I really don't know what can happen :-/ It's amazing.
Do you have an idea ?
Thank you.
You may need this
Try changing
to
The n.created was not used/needed and the DISTINCT will make sure each nid is only returned once. (The existing code will return the nid once for each term is uses)
Perfect ! Thanks Nevets :)
Perfect !
Thanks Nevets :)
deleted comment
my comment was an error, forget it, sorry.
Doesn't work with blogs
Hello,
I don't know why this doesn't work with "blog" content type...
do you ?
Thank you nevets
Thank you. This code works in 5 also and I find it very useful.
I would like to split $output into
Print $title
Print $author
Print $date
Print $teaser
Print $links (readmore)
I want to do this in order to have control over location of the variable.
How do I do that? Thanks again for the useful code.
Views would be useful for
Views would be useful for that.