Carry out the following steps:
Open
header.php
of your theme in your editor.Remove the
<body>
tag; we're going to replace it with some code, which includes the background picture.Insert the following code right where you've removed the
<body>
tag:<?php $backgroundAttribute = $c->getAttribute('background'); if ($backgroundAttribute) { $backgroundFile = $backgroundAttribute->getRelativePath(); echo "<body style=\"background:url('{$backgroundFile}')\">"; } else { echo "<body>"; } ?>
Reload your page and you'll see the new background picture instead of the color gray.
We removed the static body tag and inserted some PHP code to fetch the attribute value. This works by using $c->getAttribute
. $c
is a global variable referring to the current page.
getAttribute
is a method available on all collection objects like pages. This method works for all attributes but depending on the attribute...