0
votes

I have a page.tpl.php where I want to display images inside a div. So I created a custom content type called "Slider" , then I created a field called "image" where the machine_name for it is "field_image_slider".

Then I started adding contents (content->add content->Slider ..)

The problem is that I don't know how to display the images of this custom content! what is the PHP code that I should place inside page.tpl.php in order to display the fields of this custom content?

This is node.tpl.php :

    <?php 

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

    ?>

And this is page.tpl.php :

    <div id="banner_slides" class="owl-carousel owl-theme">

       <?php 
          if (!empty($node)) :
            $fieldImage = field_get_items('node', $node, 'field_image_slider');
                if ($fieldImage):
                   print '<div class="item"><figure><img src="' .file_create_url($node->field_image_slider['und'][0]['uri']). '" /></figure><h3 class="orange">Hi</h3></div>';
                endif; 
           endif; 
        ?>

    </div>
2
You need to review Drupal theme, it seems you mix between tpl files, page.tpl is something and node.tpl is something else, check Overview of theme files - Ziftman

2 Answers

0
votes

The fields of a node are shown in node.tpl.php If you want a field to show in that template, you need to enable it in the field display of the contenttype (admin -> structure -> content types -> [type name] -> manage display.

Here you can change the visibility of the label or change the display of the field itself.

0
votes

   <?php 
      if (!empty($node)) :
        $fieldImage = field_get_items('node', $node, 'field_image_slider');
            if ($fieldImage):
               print '<div class="item"><figure><img src="' .file_create_url($node->field_image_slider['und'][0]['uri']). '" /></figure><h3 class="orange">Hi</h3></div>';
            endif; 
       endif; 
    ?>

</div>