Multiple 'random header' images for different pages

Home Forums Theme Stuff Multiple 'random header' images for different pages

This topic contains 23 replies, has 2 voices, and was last updated by  Rev. Voodoo 5 years, 3 months ago.

Viewing 9 posts - 16 through 24 (of 24 total)
  • Author
    Posts
  • #1313

    Andy
    Member

    Oh, and I’m guessing I’d remove the random header image functions from the functions.php that I used (I used the one you posted on a tut before ).

    Thanks!

    #1314

    Rev. Voodoo
    Keymaster

    Hm… I haven’t posted any random image tut I don’t think. Maybe you are talking about the default image rotator built in to 2011? Trying to get randomization in to 2011, for different pages, while still using the default rotator is difficult. We could probably take off the last bit of the code above, the else part, and that way if the condition isn’t met, the regular 2011 random feature is used. But then we’d have to edit header.php to use your random image under certain conditions, or use 2011 built in stuff otherwise. It’s starting to get a bit complicated!! I’d love to play around with it more, but school is back in, and work is in double shifts…. I have no time right now.

    #1315

    Andy
    Member

    That’s cool man – I really appreciate you taking the time to look at it the way you are! The way you’ve posted is going to work I think!

    I’m testing at each step – so having just plugged in the rotator.php into a rotate folder and removing the random header image function from my child functions.php (I think you posted up an implementation of a modified twentyeleven random header function meaning you can use your own images without it falling apart if/when twentyeleven gets updates rather than a straight out tutorial – it was in the replies to a different tutorial about resizing images I’ve been using as a reference for many different things and man this sentence in brackets is getting way too long) no header image shows – which is correct!

    Now, plugging in images into the rotate folder – works!

    Next step – conditionalising it for those pesky pages

    Thanks again mate – it must be hard studying and doing work as well!

    Andy

    #1316

    Andy
    Member

    Well, I’m making some progress again at last. Things aren’t as good as I thought though – the cached pages in firefox made me think I was doing better than I was. The site still works which is one thing – so I guess I’m going to link to the header image from within the header.php. The only img src I can find in the document is the one referring to the image with echo back of width and height (line 94 in my header.php).

    I then plopped the image link into a page just to see if it works and it doesn’t. I’m really confused now as I can’t seem to find the code I had that worked!

    I’ll have a look at it again, maybe later tonight, but probably tomorrow now (maybe if I can sneak a bit of time in on a break at work).

    Anyway, thanks again Rev.

    Cheers,

    Andy

    #1317

    Andy
    Member

    OK – got the non-conditional one to work!

    Next step – getting the conditional ones to work on the location pages

    Thanks so much Rev – couldn’t have got this far without your help!

    Andy

    #1318

    Andy
    Member

    OK – hit a snag now!

    It appears that when making a custom php file (i.e. the rotator.php in my case) then you have to use require_once to get it to work. However, this would be from the wp-load.php which is a really dirty way of doing it as you have to use absolute links. I tried to require_once path/to/query.php as it holds the function is_page, but my error log comes flying back with php failures.

    I’ve seen another solution which will require a header and rotator file for each section (standard images, phuket, pattaya and samui) but would work nicely and would be simple copy and paste.

    It would basically use:

    if ( is_page($page) ) :
    get_header(‘/path/to/$page’);

    (sorry if that doesn’t make much sense – it makes sense to me).

    So, the generic header.php would have the conditional statements of ‘if_page’ then fling you to the correct folder, which would basically hold the same files but with different names. It’s a bit messy and I’m worried about page load times – will the fact that one php file sends you to another and then to another cause significant slowdown? Perhaps I should just try it and get it working first!

    Thanks,

    Andy

    #1319

    Rev. Voodoo
    Keymaster

    I was worried that since we were calling the php file through an img link, the conditionals wouldn’t pick up. I wasn’t 100% since I didn’t get a chance to test. Looking at that file though, you never need to use an include to use the rotator. So my next idea was going to be along the same lines as yours. Move the conditionals to the header, an use if is page ‘blah’ the img src path/to some images. elseif is page ‘blah2’ img src path top a different rotator file. PHP load times are negligible in this situation, so loading from header.php to rotator.php to an image will be nearly the same time as loading an image into header.php.

    #1320

    Andy
    Member

    Hey Rev!

    Guess what? I’ve got it to work! So I’ve been working through the WordPress codex and made a new header.php using just the is_page function with an array for the page id’s that relate to the location. Then the ‘then’ part of the if/then/else uses the get_header($name) function which refers the page to a file ‘header-$name.php’ which is great – so basically:

    if ( is_page (array(x, y, z)) ):
    get_header(blurb);
    elseif blah blah blah
    else:
    get_header();
    endif

    tadah! that was the final bit!

    Everything else was just making sure everything was pointing in the right direction. I used the get_stylesheet_directory_uri() function alot as well, and when inserting the rotating image url make sure you still include the image width and height or it whitescreens the site.

    So – thanks very much for taking me on this little journey Rev! Now I’ve got over this major stumbling block I can carry on and get on with stuff I consider to be a bit ‘easier’ than this.

    Next thing is getting uniform font styles and colours across a couple of plugins, as well as using your guide to create some colour schemes for the theme to show to the client.

    Thanks alot mate – I’ll keep posting up here when I find something useful or maybe ask more questions (if you don’t mind).

    I’m going to celebrate with a bottle of Singha now!

    Cheers,

    Andy

    #1321

    Rev. Voodoo
    Keymaster

    I’m really happy you were able to work through this!! It always feels pretty good to get to the bottom of an issue! Sometimes I’m really busy, sometimes not, but I’m always here – and try to be helpful when I can!

Viewing 9 posts - 16 through 24 (of 24 total)

You must be logged in to reply to this topic.