I need to add a slideshow (each slide containing headline, image & html text) in my frontpage. I've decided to create a custom content type named slideshow which should have above fields.

I've figured out the necessary .tpl.php file (page--front.tpl.php) in which I'll add codes to go for the slideshow.

What I've done already

  • Created a custom content type named slideshow with all the appropriate fields
  • Added all the necessary html for the slideshow in the .tpl.php template file - with necessary javascripts already included using the .info file of my theme.

Now the problem:

  • I think I'll fetch data from database & populate the variables needed in .tpl.php file in: preprocess function of template.php file of the theme. How do I retrieve the fields of slideshow content type from database?

Please help!

  • BTW I'm using Drupal 7
    – Shafiul
    Commented Oct 18, 2011 at 16:14

2 Answers 2


If I understand well your question, I guess that node.tpl.php is more suitable for use templates per content types an control over individual fields:

page.tpl.php: Default theme implementation to display a single Drupal page.

node.tpl.php: Default theme implementation to display a node.

About how to name your templates according your needs, see this documentation: Drupal 7 Template Suggestions http://drupal.org/node/1089656. Regarding your case, I guess, a template for content type, the name could be node--slideshow.tpl.php. see this answer that have information related with node.tpl.php.

and about how to see your fields, the same link to the answer have one example:

I have a field called field_demotext1, then this is the way that I can use to call their respective value inside any custom html zone of a node layout:

print $content['field_demotext1']['#items'][0]['value'];

whit print_r($content); (or dsm($content); if you use Devel module) you will see fields that can be pulled. this screenshot is using dsm($content); related with the example;

dsm $content

Render Drupal API is an alternative to the previous way. In this way you does not need seek the file using dsm() or print_r()

print render($content['field_demotext1']);

Also, seems that field_view_field is another alternative to render Drupal fields. see this related document:

I hope information be useful.

  • Thanks @MoonWatcher for taking time to answer elaborately... I'll check it out & notify you soon.
    – Shafiul
    Commented Oct 19, 2011 at 0:59
  • 1
    Is there a particular reason for advocating directly poking around $content instead of leveraging render() ?
    – mpdonadio
    Commented Oct 19, 2011 at 1:00
  • Hi @MPD, no, I do not use render(), I am not familiar with render() (I am not familiar with lots of common functions of Drupal). render($content['FIELD_NAME']); works for show a particular field, your suggestion is very useful. I will update the answer with your suggestion. Also field_view_field() seems another useful alternative.
    – cigotete
    Commented Oct 19, 2011 at 3:41
  • @moon.watcher I used it & it works perfectly (I used view template files though) but unfortunately I'm getting formatted data which is undesirable for my purpose (breaks slideshow mark-up). Thanks for helping out... will you mind checking my new question? drupal.stackexchange.com/q/13579/3235 - thanks in advance!
    – Shafiul
    Commented Oct 19, 2011 at 18:17

First solution :

Use the function "db_select" and make a SQL query

Second solution :

Utiliser the function "node_load" but it will get the node you want.

  • That means, I need to (study and) work with DB API? :( Hope there would be some easy-to-use functions already defined for retrieving fields of content types.
    – Shafiul
    Commented Oct 18, 2011 at 16:26
  • I'm thinking of making DB API calling. +1 for suggesting :)
    – Shafiul
    Commented Oct 19, 2011 at 18:19

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.