Hello all,

Hope someone can help me with this. What I need to do is to display the last node of a specific category with a teaser. I found something close to what I want but it displays some information I don't want displayed. I only want the title with a link a date and a teaser. No user info or category or commenting option.

Any help would be appreciated.

Comments

he_who_shall_not_be_named’s picture

<?php
  $sql = 'SELECT 
      nid, 
      title, 
      teaser
    FROM 
      {node} n 
    WHERE 
      status = 1 
    ORDER BY 
      changed desc
    LIMIT 0, 1';
    
  $sql = db_rewrite_sql($sql);
  $result = db_query($sql);
  if($node = db_fetch_object($result)) {
    print($node->teaser);
  }
?>
jwilde’s picture

Hi vrencianz,

I'm trying to change the similar.module (4.7) to display teasers, any ideas?

Thanks,

Jim

Saudi-1’s picture

Thanks for the help, unfortunately that didn't work.

user warning: Unknown column 'teaser' in 'field list' query: SELECT FROM WHERE ORDER BY changed desc

he_who_shall_not_be_named’s picture

Try this one, then. I can't test it, because I have no Drupal 4.7, but it must work.

  $sql = 'SELECT
      n.nid,
      nr.title,
      nr.teaser
    FROM
      {node} n
      join {node_revisions} nr
      on (n.nid = nr.nid and n.vid = nr.vid)
    WHERE
      n.status = 1
      and n.type = \'story\'
    ORDER BY
      nr.timestamp desc
    LIMIT 0, 1';
    
  $sql = db_rewrite_sql($sql);
  $result = db_query($sql);
  if($node = db_fetch_object($result)) {
    print($node->teaser);
  }
Saudi-1’s picture

I don't know what happened but I keep getting this error on every page for no apperant reasion as far as I can see.

user warning: Unknown column 'teaser' in 'field list' query: SELECT FROM WHERE ORDER BY changed desc .LIMIT 0, 1 in /***t/****/***/includes/database.mysql.inc on line 124

he_who_shall_not_be_named’s picture

It seems that you didn't changed the query. There is the old one.

Saudi-1’s picture

I deleted it but the message stills appears everywhere. I have no idea whats wrong?

Saudi-1’s picture

never mind, I need my head examined. thanks for the help.

Saudi-1’s picture

This works nicely thanks :)

Just one more question. How could I display the title and the ink?

he_who_shall_not_be_named’s picture

print(l('</h3>' . $node->title . '</h3>', 'node/' . $node->nid));
Saudi-1’s picture

Thanks for the help. really appreciate it.