- This topic has 7 replies, 3 voices, and was last updated 4 years ago by
David.
-
AuthorPosts
-
March 7, 2019 at 9:54 am #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???
GeneratePress 2.2.2GP Premium 1.7.8March 7, 2019 at 4:00 pm #832275Tom
Lead DeveloperLead DeveloperHey 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 towp_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 ๐
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentMarch 8, 2019 at 2:06 am #832580Hans
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.
March 8, 2019 at 8:15 am #833019David
StaffCustomer SupportHi there,
the image URL is 404’ing – i tried opening it directly in the browser.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/March 8, 2019 at 9:23 am #833093Hans
March 8, 2019 at 9:27 am #833097David
StaffCustomer SupportSorry same issue – that page the button links to has a background image this is 404’ing.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/March 8, 2019 at 10:52 pm #833462Hans
Hi David,
thanks for your help and patience. There were two problems:
1. an erroe in the url-path
2. a corrupt jpg-fileNo everything is working.
March 9, 2019 at 4:05 am #833649David
StaffCustomer SupportGlad to hear you figured it out ๐
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/ -
AuthorPosts
- You must be logged in to reply to this topic.