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

leoklein’s picture

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.

Anonymous’s picture

Why a script when you can use the views module?

leoklein’s picture

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.

Anonymous’s picture

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.

leoklein’s picture

Yeah, I know but I'm talking about RSS Feeds. Views can produce no RSS Feeds that contain CCK Fields.

Anonymous’s picture

My simplicity, .....

jarea’s picture

Any idea how to modify this select to get only the most recent blog entry per user?

Thanks for the help.

.carey’s picture

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)

<?php
/**
* the following displays a list of the 10 most recent weblog titles
* and links to the full weblogs of a certain user.
* If you want to increase/reduce
* the number of titles displayed..simply change the $listlength value
*
* for a different user change the $userid value
*
* works with drupal 4.7.
*
*/
$listlength="1";
$userid="2";

$output = node_title_list(db_query_range(db_rewrite_sql("SELECT n.nid, n.title, n.created FROM {node} n WHERE n.type = 'blog' AND n.uid = $userid AND n.status = 1 ORDER BY n.created DESC"), 0, $listlength));

echo "<div class=\"blogtitle\">" . $output . "</div>";
?>

Carey

jarea’s picture

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

4wding’s picture

Hi Jarea,

Not sure if you have solved this one yet, but you could use something like the following:

/**
*
* works with drupal 5.1.
*
*/
$listlength="10";

$output = node_title_list(db_query_range(db_rewrite_sql("SELECT n.nid, n.title, n.created FROM {node} n WHERE n.type = 'blog' AND n.status = 1 GROUP BY n.uid ORDER BY n.created DESC"), 0, $listlength));

echo "<div class=\"blogtitle\">" . $output . "</div>";

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.

leoklein’s picture

Since I was using CCK fields, the information about the image was in a separate table. Here's what I eventually hacked together:

  $sql = "SELECT node.title, node.nid, node.created, content_type_webcite.field_image_title 
    FROM node INNER JOIN content_type_webcite ON node.nid = content_type_webcite.nid 
    WHERE (content_type_webcite.nid = node.nid) AND node.status = 1 
    ORDER BY node.created DESC 
    LIMIT $list_no";

It's what powers the "Widget" on my new site:
http://libsite.org/widget

lias’s picture

subscribing...

Cross_and_Flame’s picture

How does that grab the image links?

John98’s picture

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. . . . . . . . . . . . .