PHP

Create a Recent Posts Block in Drupal

I needed to make a block in drupal that contain my recent posts and so, I write this code snippet.

<?php

// Get all node IDs and it title from the "node" table
// Customize the types retrieved from the "type" field
// (Status=0 & Moderate=0) mean the post is published
$result = mysql_query("SELECT nid, title
                       FROM node
                       WHERE (type='story' or type='blog'
                              OR type='flexinode-1')
                       AND NOT (status=0 and moderate=0)
                       ORDER BY nid DESC"
)
                       or die(
mysql_error());

echo "<ul>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
  
// Print node titles linked to its page into unsorted list
  
echo "<li>";
   echo
"<a href=\"http://ikhnaton2.com/
            node/{$row['nid']}\">$row['title']}</a>"
;
   echo
"</li>";
}
echo
"</ul>";

?>

Enjoy :)

Another trick: Display a list of node titles from a specific category

Convert Date/Time to Unix Timestamp using PHP

Very helpful function to convert date/time string to Unix timestamp. I needed this function to update the timestamp field of some comments in my Drupal after migrating them from my blog on blogspot.

Retreiving Information from MySQL using PHP

If you need to get data in your MySQL database and display them on your dynamic PHP page.

In this example we will select everything in our table "example" and put it into a nicely formatted HTML table.
Syndicate content