I want to theme the Recent Content block with associated thumbnail of each node. After researching for a long time I found the function node_get_recent()
. This function selects data from table ‘node’, but this table doesn’t include any url pointing to the url of an image, which means I am not be able to use $node->(url of this thumbnail) to fetch its thumbnail. I happend to find the url of the thumbnail is located in the table ‘file_managed’, but I still cannot associated it with table ‘node’ through leftjoin.
I do not know how to do it the right way. I do not want to use Views. Thanks!
When I put the following code into my .module file the title displayed for each node is the same.
function example_contents() { $number_of_post = 10; $result = db_query("select n.title,n.nid,f.entity_id,fm.fid,fm.uri from {node} n left join {field_data_field_image} f on n.nid=f.entity_id left join {file_managed} fm on f.field_image_fid=fm.fid limit $number_of_post"); $items = array(); foreach ($result as $node) { $items[] = l($node -> title,'node/'.$node -> nid); } return array('#markup' => theme('item_list', array('items' => $items))); }
$node -> title
turned out to be same, however $node -> nid
worked. That is to say the list of nodes used the same title but different urls. What was wrong with my code? Secondly, I do not know where to put my $node -> uri
into $items[]
in order to display the thumbnail.