1

How to add image to only front page of Drupal 7 website ?

So for now I have this code:

<div id="content-wrapper">
    <img src="/sites/default/files/Front_Page_Pic.png" width="100%"/>
    <?php
    if (!drupal_is_front_page()) {
        echo render($page['content']);
    } else {
        echo render($page['reference']);
    }
    ?>
</div>

But this means that on everypage it will show my image.

Any idea how can i fix it ?

0

4 Answers 4

2

Here is another approach:

  • create "a" node (pick whatever content type you want), say it's node id is 123 (generated automatically by Drupal when you save it). Or add a "path" to it like my_page_with_image.
  • include that image in that node and make sure your input filter that you use (i.e if you use "filtered HTML", which is what I'd recommend) accepts "images".
  • set node/123 as your frontpage (or my_page_with_image instead, if you added a path for it).

Next question? Maybe "How do I set that page as my frontpage"? ... Ask (via a new question, only 1 question per 'question' here ...) and pretty sure you'll get the answer to that question to ...

PS: What is so special about all your pages where you are considering using PHP for it's actual content? You are aware that using PHP for those things is in general NOT recommended, right? And that you have to be very carefull in which user "roles" will be allowed to create such pages ...

1

Drupal has its own way to theming and displaying content , and its not easy so i suggest you to use modules in this case , so first of all install Image Block module , you can now easily create a block containing a photo. in the next step go to block configuration and set the block to be displayed only in front page , token may help you ;)

1

Another way

1.Create a block add image and display on front page.

2.You can also create separate tpl file for front page.

0

Add the page--front.tpl.php into your theme folder. Print the image in this Tpl.

For further info on front page template files refer - Customize the front page template

3
  • So as far as i know this is the code ?: <img src="<?php print $directory; ?>/sites/default/files/Front_Page_Pic.png" /> ?
    – ZeroByte
    Commented Jul 31, 2015 at 14:25
  • Yes this would do it. Commented Jul 31, 2015 at 14:27
  • I get the fatal error: Parse error: syntax error, unexpected '<' in /var/www/vhosts/httpdocs/sites/all/themes/mater/templates/page.tpl.php on line 124 The line which i add this code.
    – ZeroByte
    Commented Jul 31, 2015 at 14:30

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.