-
AuthorPosts
-
January 24, 2019 at 1:51 pm #1058143
Hi,
In my page I have a header image placed in a color section with background image, Title and subtitle.
So that I can reuse the same element I built this header as a page so I can include it as a content element into some of my pages. Now I placed the page title as it is, the subtitle from custom fields. Is there a possibillity to use the post thumbnail or page default image as the background for the color section?
css or a shortcode?Thanks in advance.
Onlineplaner- This topic was modified 5 years, 11 months ago by Onlineplaner.
January 24, 2019 at 3:31 pm #1058190Hi Enfold team,
I managed to solve this by adding functions to child theme function.php and some css and a custom field in the page
In case someone needs to do the same. Here is the code I used.
Add to functions.php of child theme:add_shortcode( 'page_title', 'page_title_sc' ); add_shortcode('field', 'shortcode_field'); function shortcode_field($atts){ extract(shortcode_atts(array( 'post_id' => NULL, ), $atts)); if(!isset($atts[0])) return; $field = esc_attr($atts[0]); global $post; $post_id = (NULL === $post_id) ? $post->ID : $post_id; return get_post_meta($post_id, $field, true); } add_shortcode('thumbnail','thumbnail_in_content'); function thumbnail_in_content( $atts ) { global $post; return get_the_post_thumbnail_url( $post->ID ); }
Add to content in the color section of the header template page:
<h1>[page_title]</h1> <p>[field "Subtitle"]</p> (Create a custom field with the name Subtitle)
and css in header template
<style type="text/css"> #top #wrap_all #main .avia-no-border-styling { background-repeat: no-repeat; background-image: url([thumbnail size=full]); background-attachment: scroll; background-position: center center; background-size: cover !important; </style>
Maybe there is an easier solution. But this one did the job for me.
- This reply was modified 5 years, 11 months ago by Onlineplaner.
January 25, 2019 at 7:47 am #1058511 -
AuthorPosts
- You must be logged in to reply to this topic.