Site logo

[Support request] Is it possible to show a random page header?

Home Forums Support [Support request] Is it possible to show a random page header?

Home Forums Support Is it possible to show a random page header?

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #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,
    Marjon

    #305625
    Leo
    Staff
    Customer Support

    Hi Marjon,

    Not sure what you meant by Random? Can you explain it a little more?

    #305783
    Marjon 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!

    #305901
    Leo
    Staff
    Customer Support

    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!

    #307111
    Marjon 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 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&#8217;,
    http://dewebruimte.nl/doortechnics/wp-content/uploads/2017/04/Slider-2.jpg&#8217;,
    http://dewebruimte.nl/doortechnics/wp-content/uploads/2017/04/Slider-3.jpg&#8217;,
    );

    $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

    #307338
    Leo
    Staff
    Customer Support

    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="" />';
    
    ?>
    #307683
    Marjon 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

    #307763
    Tom
    Lead Developer
    Lead Developer

    Just jumping in.. Are you adding that code into GP Hooks or into the Page Header meta box?

    #307842
    Marjon 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,

    #308010
    Tom
    Lead Developer
    Lead Developer

    GP Hooks is the correct area. Did you check the “Execute PHP” checkbox?

    #308122
    Marjon 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.

    #308138
    Marjon 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,

    #308205
    Tom
    Lead Developer
    Lead Developer

    Can you link me to a page where it’s not working with your picture links?

    #308209
    Marjon 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).

    #308220
    Tom
    Lead Developer
    Lead Developer

    Ah, Sections don’t have the before content hook.

    Maybe try the Inside Content Container hook?

Viewing 15 posts - 1 through 15 (of 15 total)
  • You must be logged in to reply to this topic.