By leoklein on
I need to snatch the 'n' most recent Node Titles and Image Links.
I was looking at the snippet and while they're all for 4.7, this one seemed to work:
<?php
/**
* This php snippet displays the 10 most recent weblog entries with
* teaser & info.
*
* To increase/decrease the number of weblogs listed
* change the $listlength field to suit.
*
* Works with drupal 4.6
*/
$listlength=10;
$result1 = pager_query(db_rewrite_sql("SELECT n.nid, n.created FROM {node} n WHERE n.type = 'blog' AND n.status = 1 ORDER BY n.created DESC"), $listlength);
while ($node = db_fetch_object($result1)) {
$output .= node_view(node_load(array('nid' => $node->nid)), 1);
}
print $output;
?>
My first question is: It says, "Works with drupal 4.6" so is it the best way to go for 5.x?
Then, next, how do I get the title (n.title?) and other parts of it out (like the image link)?
Any help would be appreciated.
Comments
Important to Specify Content Type
I have several content types, so it's important to specify one (in this case 'blog') as part of the query. Also, when I say "worked" above, I mean it got me the entire node.
Views?
Why a script when you can use the views module?
Views Doesn't Work with CCK Fields
The only thing that shows up with Views are standard node fields like Title and Body. If you've created any CCK fields (such as an image_field), faggedaboutit.
At the moment, the only "easy" solution is Contemplate, but as I said you can have only one version per content type and I already have a full version for RSS readers.
There doesn't seem any other alternative than to create my own version from scratch. That means, using SQL to grab the information I need from the database and then adding tags myself.
I think Views work with CCK fields
It could be that the views solution is not the solution for you, becaus you want another lay-out. But views works with cck fields: image tekst, email,.. all this field are selectable in views.
Views Doesn't Work with CCK Fields -- for RSS feeds!
Yeah, I know but I'm talking about RSS Feeds. Views can produce no RSS Feeds that contain CCK Fields.
OK, now I understand
My simplicity, .....
Latest entry per user
Any idea how to modify this select to get only the most recent blog entry per user?
Thanks for the help.
Maybe Helpful?
I'm not sure if this is what you're looking for or is at least helpful for modification, but this is what I use (found here on Drupal) to display the title of the latest blog entry of a specific user. (Also, I don't know if this works for 5.x)
Carey
Carey thanks, That is close,
Carey thanks,
That is close, but I am looking for a select for the latest post of ALL of the blogs on the site.
jarea
Try using select IN
Hi Jarea,
Not sure if you have solved this one yet, but you could use something like the following:
I've not tested this though, so it may not work :). I've set the listlength to 10, but you may want to leave this out if you really want ALL the users latest posts. Can also change n.created to n.changed if you want most recently updated nodes.
Actually It Was Harder Than I Thought
Since I was using CCK fields, the information about the image was in a separate table. Here's what I eventually hacked together:
It's what powers the "Widget" on my new site:
http://libsite.org/widget
subscribing...
subscribing...
images?
How does that grab the image links?
My first question is: It
My first question is: It says, "Works with drupal 4.6" so is it the best way to go for 5.x?
Then, next, how do I get the title (n.title?) and other parts of it out (like the image link)?
Any help would be appreciated. . . . . . . . . . . . .