[Resolved] Dynamic background

Home Forums Support [Resolved] Dynamic background

Home Forums Support Dynamic background

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #831974
    Hans

    Hi,

    I followed your advice: Link. All trials to get an image with this code failed. I tried it with Elements and Hooks, nothing was successfull.

    Where should I place the code?

    In addition it is more complicate. What I want to achieve:

    I have a page with a parameterized shortcode – see attached link. In dependence of the parameter for this shortcode I output different information from database tables. This part works very well. But in addition I would like to outut different backgrounds. Is it possible to realize this by PHP in combination with CSS or even with GP???

    #832275
    Tom
    Lead Developer
    Lead Developer

    Hey Hans,

    Where is the background image URL coming from? A custom field?

    If so, you could:

    1. Create a Hook Element: https://docs.generatepress.com/article/hooks-element-overview/
    2. Set the hook to wp_head
    3. Check “Execute PHP”

    Then, inside the hook content, you can do this:

    <?php
    if ( is_singular() ) :
        $url = get_post_meta( get_the_ID(), 'your_custom_field', true );
        
        if ( $url ) : ?>
            <style>
                body {
                    background-image: url('<?php echo $url; ?>');
                }
            </style>
        <?php endif;
    endif;
    ?>

    Let me know if that helps or not ๐Ÿ™‚

    #832580
    Hans

    Hi Tom,

    I followed your advice. I created a Hook Element with Display Rule for the specific page. This is the code:

    <?php
       $url = 'http://huppenbroich.de/simwae/wp-content/wkfotos/wk-' . $_POST['stbez'] . '.jpg'; ?>
        <style>
           body {
               background-image: url('<?php echo $url; ?>');
           }
        </style>

    The image is loaded – but not displayed. There seems to be a problem in CSS.

    Could you please investigate it.

    #833019
    David
    Staff
    Customer Support

    Hi there,

    the image URL is 404’ing – i tried opening it directly in the browser.

    #833093
    Hans

    I probably change the URL. Please try:

    Link

    and then press the button: Wahlkreis Button 1 1

    Sorry!

    #833097
    David
    Staff
    Customer Support

    Sorry same issue – that page the button links to has a background image this is 404’ing.

    #833462
    Hans

    Hi David,

    thanks for your help and patience. There were two problems:

    1. an erroe in the url-path
    2. a corrupt jpg-file

    No everything is working.

    #833649
    David
    Staff
    Customer Support

    Glad to hear you figured it out ๐Ÿ™‚

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