I created a content type: "period".

Then, I created instances of this content type.

Now I would like, on a page tpl.php put the instructions, to print all the titles of the instances that I put on this content type. is it possible?

  • To print list of items you can use Views module.
    – kalabro
    Nov 9, 2012 at 12:58
  • I would have an array with instances of the content type ...
    – Antilope
    Nov 9, 2012 at 13:03

1 Answer 1


I think the "best" way (most future-proof etc.) would be to use an EntityFieldQuery:

$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
  ->entityCondition('bundle', 'period');

$results = $query->execute();
if (!empty($results['node'])) {
  $nodes = node_load_multiple(array_keys($results['node']));
  foreach ($nodes as $node) {
    // Do something with $node->title

There are other options but they either involve deprecated methods or going directly into the node/revision tables, which can be a pain.

If you need this list in page.tpl.php make sure you don't put the code directly in the template file (it's bad practice and can cause problems with caching). The best place would be in a preprocess hook in your theme's template.php file, or a module file.

  • hello, thanks for your explanation. I plan not long in Drupal and PHP code I put in the template. How should I do? You have something for me to read? thanks ...
    – Antilope
    Nov 9, 2012 at 14:05
  • I think Setting up variables for use in a template would probably be the best place to start
    – Clive
    Nov 9, 2012 at 15:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.