Jump to content


Photo

Random header on most pages BUT not ALL


  • Please log in to reply
6 replies to this topic

#1 deadlytim

deadlytim

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 04 December 2011 - 01:44 PM

Hello there oh wise forum. Please bring me help... I'm looking to make my blog have random headers on most but not all pages. For example on the page: http://harringtonand...unpleasantries/ I want the image http://harringtonand...leasantries.jpg On general pages I want to pull randomly from the http://harringtonand...om/img/headers/ directory- yes they are all the same size. From my searching it seems like this is a job from the custom section of Pagelines but I haven't been able to get it to work. I'm not sure how to target CSS type changes to a specific page. Is it .unpleasantries or something? Or a page ID? Is the random image thing a totally unrelated issue to the "hard coded" headers for specific pages? How do they play together? I'll be adding more pages with specific headers as well as more random headers soon so the solution needs to be extensible. Thanks for any help! FWIW I sacrificed a goat to the Forum God in hopes of a speedy and clear response. I dropped the goat into my USB port like it was a volcano. ;-)

#2 Rob

Rob

    One Smart Egg

  • Members
  • 13575 posts
  • LocationEast Coast, USA
  • Framework Version:The Latest, of course
  • Country: Country Flag

Posted 04 December 2011 - 02:45 PM

Wow, this is a challenge that requires some divine inspiration! One strange thought that comes to mind would be to replace the branding image with an ad injection using a combination of plugins plus OpenX, an ad management script. Check this plugin: http://wordpress.org...s/ad-injection/ OpenX installs totally separate from WordPress, but the plugin coordinates with it, bringing the appropriate code into WordPress, and thus into your header. You would treat each individual header as an ad that will be placed only on certain pages or posts. The code needed would be provided by the plugin. As a result, you simply schedule the different ads to appear on different pages according to your wishes. There are also other ad management plugins available at http://www.wordpress/extend/plugins and you're free to search for something you think might be easier. In any case, the essential changes need to be made in functions.php and/or the applicable template, depending on the method you need. Some CSS might also be needed to position the ad/image where you want it.

#3 deadlytim

deadlytim

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 04 December 2011 - 03:59 PM

hmmm... I was able finally to get different header images to work- Used a clear gif as the header image in global options and added this to the custom CSS #branding .branding_wrap{ background: url('http://harringtonandselves.com/img/headers/header-time.jpg') no-repeat 0 0 transparent; height:84px; } body.page-id-139 #branding .branding_wrap{ background: url('http://harringtonandselves.com/img/headers/header-unpleasantries.jpg') no-repeat 0 0 transparent; height:84px; } For the random could I replace: #branding .branding_wrap{ background: url('http://harringtonandselves.com/img/headers/header-time.jpg') no-repeat 0 0 transparent; height:84px; } with a php script that returns a random value for url()? I know how to do this kind of thing if you could tell me where in which file to start messing with. Something in the themes css directory?

#4 catrina

catrina

    Advocate

  • Members
  • 12345 posts
  • LocationCalifornia
  • Country: Country Flag

Posted 04 December 2011 - 04:26 PM

What are you looking to do with the random value for url()?

#5 deadlytim

deadlytim

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 14 December 2011 - 06:26 PM

What I want to do is have different versions of my header graphic load randomly each time. I was thinking I could code something to randomize the value of background: url #branding .branding_wrap{ background: url('http://harringtonandselves.com/img/headers/header-time.jpg') no-repeat 0 0 transparent; height:84px; }

#6 kastelic

kastelic

    Advocate

  • Members

  • 3081 posts
  • Country: Country Flag

Posted 14 December 2011 - 11:28 PM

Here's a php script that will do this:
Paste into platformbase/functions.php.

 
	//RANDOM HEADER BG
	add_action('wp_head','random_url');
	function random_url(){
		$url_list = array(
			'http://harringtonandselves.com/img/headers/header-time.jpg',
			'http://harringtonandselves.com/img/headers/header-unpleasantries.jpg'
		);
		shuffle($url_list);
		?>
		<style type="text/css">
		#branding .branding_wrap{
			background: url('<?php echo $url_list[0] ?>') no-repeat 0 0
		}
		</style>
		<?php
	}
	


#7 deadlytim

deadlytim

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 29 December 2011 - 02:48 AM

Perfect! Thanks a lot!