I've looked around everywhere but basically I just want the PHP code that displays the latest blog entry teasers like you'd see on the front page for use in a template. Thanks!

Comments

Wesley Tanaka’s picture

You can find it in the node_page_default() function (it's pretty short)

Wesley Tanaka | Drupal Stuff

vinayras’s picture

Hi,

You need to query two tables for this, i.e Node & Node Revisions


$limit=10; // number of records to fetch

function get_nodes($limit) {

$sql = "SELECT n.nid, r.vid, n.type, n.status, n.created, n.changed, n.comment, n.promote, n.sticky, r.timestamp AS revision_timestamp, r.title, r.body, r.teaser, r.log, r.format FROM {node} n INNER JOIN {node_revisions} r ON r.nid = n.nid WHERE n.type='blog' AND n.status=1 ORDER BY n.created DESC";


  $result = pager_query($sql, variable_get('default_nodes_main', $limit));

    while ($anode = db_fetch_object($result)) {
       //$changed = date('d/m/y', $anode->changed);
       $items[] = l($anode->title, "node/". $anode->nid) . " - ".format_interval(time() - $anode->created)."<br>".strip_tags($anode->teaser);
    }

    if(!$items) {
        return;
    } else {
        return theme_item_list($items);
    }
}


echo get_nodes(10);

This should work.

Vinay Yadav
PHP / Drupal Specialist
http://www.vinayras.com

MercWorks’s picture

Thanks to both of you for your replies. I did as instructed in the first reply and got

   print node_page_default();

which seems to work fine. Is there any advantage to using your method, Vinay?

www.mercworks.net

tsavino’s picture

Where do you put this in a page?

vm’s picture

create a page content type add the code to a page. switch your input format to php and submit.
_____________________________________________________________________________________________
give a person a fish and you feed them for a day but ... teach a person to fish and you feed them for a lifetime

BruceLerner’s picture

This code does exactly what was needed.

tiki16’s picture

Hello, is there a way to have the 'read more' link below the teaser?
thanks