We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 6715
    • 4 Posts
    On ExploretheBruce.com we had to give the site managers the ability to change the headers on each of the pages. They wanted to be able to have video headers on some pages, and image headers on other pages. They wanted it so that when they assigned a header on a parent page, that all its children showed the same header.

    Here’s how we did it (not saying it is the best way)

    We added a template variable called header-image. It had the input type of File.

    We then added a snippet called page-image.

    <?php /* Header Image Control on a per page basis
    This script pulls the image-header template variable and displays an image if the file is an image or a video file if it is a video.
    
    If no file is found, it should look at the parent page and see if it has a header and use it (unless the parent page uses a video)
    
    Then, if the parent uses a video header, or if the parent doesn't have a header image, it should show a default image. 
    */
    
    //Get the array that is included in grabbing the template variable
    $tv_header_row = $modx->getTemplateVar('header-image');
    //print_r($tv_header_row);
    
    //Check to make sure it isn't empty (it never should be) and then check to make sure it isn't the default image. 
    if(!empty($tv_header_row['value']) && $tv_header_row['value'] != "assets/images/default.jpg") {
    	$headerfilename = $tv_header_row['value'];
    	
    	//Grab the last three letters of the file name
    	$headerfiletype = substr($headerfilename, -3);
    	
    	//Check to see if it is a flash file
    	if ($headerfiletype == "swf" || $headerfiletype == "flv"){		
    		//echo out the code for showing a flash video
    		?>
    			<object width="680" height="238">
    			<param name="movie" value="<?php echo $headerfilename ?>" />
    			<embed src="<?php echo $headerfilename ?>" quality="high" bgcolor="#ffffff" width="680" height="239" name="<?php echo $headerfilename ?>" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" loop="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">
    			</embed>
    		</object>
    		<?
    		}else{
    		//echo out the code for showing an images
    		echo "<img src='$headerfilename' />";
    	}
    }else{
    		echo "<img src='assets/images/default.jpg' />";
    }
    ?>


    We then just call that in our page template and it shows up. Then in the template variables of any page, a Header Image control box exists where images or videos file paths can be added. So far, the two site administrators have found it very easy to use, and very effective.

    We had this feature launched and working on our site with MODx long before WordPress 3.0 came out.