How to get last X contents I want to write a function inside a module that will return last 20 contents of type X . is there any drupal ready function ? or shall i use queries ?

THanks
You can use views to get that.

Make sure you sort items descending and limit the result number to be 20.