Archived topic
Is it possible to show a random page header?
14 replies · Started by Marjon Tas on April 13, 2017
Hi Tom,
Still enjoying your theme and add ons..
One question: Is it possible to add a random page header to the homepage? I saw a hook for random header, does it work for a page header as well?
Thanks,
Best regards,
Marjon
Hi Marjon,
Not sure what you meant by Random? Can you explain it a little more?
Hi Leo,
I would like to show a random image with every click on the page. So if I come on the homepage I want to show image x, I go to a product page, and back to the homepage, the homepages shows image Y or Z, and so on. Three or four pictures that rotate in a random way.
Since I have the header fixed, I would like to do that with the page header function. I saw these tw solutions for the header and a background image:
https://generatepress.com/forums/topic/header-background-images/
and
https://generatepress.com/forums/topic/random-rotate-header-logo-per-page-view/
But I am not sure what I should do to let that work on the page header function.
Can you help me a little?
Thanks!
I think Tom's code should work (https://generatepress.com/forums/topic/random-rotate-header-logo-per-page-view/#post-154994) and we might just have to style it after.
Can you give that a shot first and provide a link to your site? Thanks!
Hi Leo,
I tried to put the code before header content and also inside content container, but I get for both a white screen error message
Method Not Implemented
POST to /doortechnics/wp-admin/options.php not supported.
My code is this:`
<?php
$headers = array(
'http://dewebruimte.nl/doortechnics/wp-content/uploads/2017/04/Slider-1.jpg',
'http://dewebruimte.nl/doortechnics/wp-content/uploads/2017/04/Slider-2.jpg',
'http://dewebruimte.nl/doortechnics/wp-content/uploads/2017/04/Slider-3.jpg',
);
$random = $headers[ rand( 0, count( $headers ) -1 ) ];
echo '<img src="' . $random . '" alt="" />';
?>
`
The link is: http://dewebruimte.nl/doortechnics/
(homepage. I use sections, and it should look at the picture beneath, the upper picture is the pageheader, the second a section).
Thanks for helping,
Marjon
Hmm I copied and pasted the code exactly below and it's working for me in the Before Header Content hook.
Can you give it another shot? Maybe don't change the picture links first just to test it out:
<?php
$headers = array(
'http://richardarmitageworld.com/images/logo1.jpg',
'http://richardarmitageworld.com/images/logo2.jpg',
'http://richardarmitageworld.com/images/logo3.jpg',
'http://richardarmitageworld.com/images/logo4.jpg',
);
$random = $headers[ rand( 0, count( $headers ) -1 ) ];
echo '<img src="' . $random . '" alt="" />';
?>
Hi Leo,
Nope, I get the same error message. It could have something to do with the hoster. The code doesn't get entrance to the wp-options files. I will ask them first. I'll get back to you if I have their response.
If you have another idea, I would love to hear it ofcourse.
Thanks,
Marjon
Just jumping in.. Are you adding that code into GP Hooks or into the Page Header meta box?
Hi Tom and Leo,
I put it into GP Hooks. The hoster did answer in the meantime. It is normally not allowed to post an 'echo' command in a form for safety reasons. They did allow it now. I tried it again. The code is accepted now, I don't get the error message, but it appears it doesn't work yet... It doesnt have any effect. So I removed the hook again.
Should the code be added elsewhere?
Thanks,
GP Hooks is the correct area. Did you check the "Execute PHP" checkbox?
Yes, I did.
I selected an image in the homepage itself as a page-header, and I put the php code in the before header content Hook. Nothing happens. I see the picture I chose in the pageheader, but not the other pictures.
Ok, another test gave this:
It works with 'before content' hook (that is where the pageheader should come). But only with the picturelinks to richardarmitageworld.com. Not with my picturelinks.
It worked only on pages which don't use section. And the homepage, the only page where they should show, uses sections.
So two 'problems'left: the imagelinks (which are correct), and how could the pageheader show on pages with sections, with this hook? I suppose I could remove it from the others pages but the homepage, by a 'display none' in the css later on.
Maybe you could help me solve this. The imagelinks might again have to do something with security from the hoster. I'll ask.
Thanks,
Can you link me to a page where it's not working with your picture links?
http://dewebruimte.nl/doortechnics/
The homepage is the only page with a page header (and sections).
The page fotoalbum does not have sections and got a pageheader when I tested the code with the other imagelinks. So it should not be there, for my purpose, but it was there working. (as well on the newspage).
Ah, Sections don't have the before content hook.
Maybe try the Inside Content Container hook?