Once Drupal is installed you will notice an option under CREATE CONTENT to create a PAGE. It is a standard out-of-the-box Drupal feature and when creating a PAGE you have 3 filter options when submitting i.e. Filtered HTML, Full HTML or PHP.

Note: PHP filter is not available until enabled.
Goto: Administer > Site building > Modules 'Core-optional' subsection.

The PHP Snippets below are intended for use within a drupal page filtered as PHP that simply enables you to "pull" specific content from your drupal database. Allowing you to create dynamic and sophisticated page layouts.

Make sure you check the custom block examples and PHP Theme Template snippets as well.

  • Very simple to use and implement. Copy and paste snippets into your page.
  • Allows users to insert "block style" content in the main page.
  • build simple or sophisticated main page layouts with dynamic content.
  • pull specific content from your Drupal database to insert into a page.

Adding new snippets

If you come up with a new snippet or a variation of an existing snippet, please post it here:

  1. Go to the page for the appropriate Drupal version (Drupal 4.5.x/4.6.x, Drupal 4.7.x, Drupal 5.x or Drupal 6.x).
  2. Use the ADD CHILD PAGE link at the bottom.
  3. Select a category to indicate which version of Drupal it is compatible with.
  4. Double-check your code for typos and that it adheres to the guidelines for writing secure code.

Dublin Drupaller

Comments

myao’s picture

I can no longer get into the site to remove the block.

Fatal error: Call to undefined function db_num_rows() in /home/content/10/6947710/html/drupal/includes/common.inc(1547) : eval()'d code on line 7

Can anyone help me to remove the snippets from the db so that I don't have to restore everything from an old backup (that mean loss of data)

francoud’s picture

No Drupal 7 page snippets entry, here?

Québec’s picture

Hi,

I have found these snippets on http://www.srikanth.me/

=> count nodes of a particular content type

<?php
$counter = db_query("SELECT count(nid) FROM {node} WHERE node.type='YOUR-CONTENT-TYPE-HERE' AND node.status=1")->fetchField();
echo "Total : $counter";
?>

=> count members

<?php
$members = db_query("SELECT count(uid) FROM {users} WHERE users.status=1")->fetchField();
echo "Registered Users : $members";
?>