- This topic has 14 replies, 3 voices, and was last updated 8 years, 6 months ago by
Tom.
-
AuthorPosts
-
April 13, 2017 at 1:23 pm #305598
Marjon Tas
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,
MarjonApril 13, 2017 at 2:15 pm #305625Leo
StaffCustomer SupportHi Marjon,
Not sure what you meant by Random? Can you explain it a little more?
April 14, 2017 at 2:00 am #305783Marjon Tas
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!April 14, 2017 at 9:05 am #305901Leo
StaffCustomer SupportI 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!
April 17, 2017 at 11:17 pm #307111Marjon Tas
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 messageMethod 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,
MarjonApril 18, 2017 at 9:08 am #307338Leo
StaffCustomer SupportHmm 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="" />'; ?>April 19, 2017 at 7:55 am #307683Marjon Tas
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
April 19, 2017 at 9:50 am #307763Tom
Lead DeveloperLead DeveloperJust jumping in.. Are you adding that code into GP Hooks or into the Page Header meta box?
April 19, 2017 at 12:06 pm #307842Marjon Tas
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,
April 19, 2017 at 8:33 pm #308010Tom
Lead DeveloperLead DeveloperGP Hooks is the correct area. Did you check the “Execute PHP” checkbox?
April 20, 2017 at 5:52 am #308122Marjon Tas
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.April 20, 2017 at 6:58 am #308138Marjon Tas
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,
April 20, 2017 at 9:51 am #308205Tom
Lead DeveloperLead DeveloperCan you link me to a page where it’s not working with your picture links?
April 20, 2017 at 9:58 am #308209Marjon Tas
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).
April 20, 2017 at 10:18 am #308220Tom
Lead DeveloperLead DeveloperAh, Sections don’t have the before content hook.
Maybe try the Inside Content Container hook?
-
AuthorPosts
- You must be logged in to reply to this topic.