Parallax header image with overlaid text

Hi,

A support question carried over from this topic:

I have been testing Ben Ryan’s Full-Width Parallax Featured Image customisation on my staging site, and I’d like to achieve a similar effect on pages.

Jade pointed out that of course I could achieve a similar effect by using a background image with parallax. But I would want the styling to match the customised blog entries.

I’d be grateful if you could take a look at my staging site and advise how to achieve the same effect on pages - how would I match the styling so that the title appears over the parallax image, and in the same position?

You will need to login as the site is behind an under construction page:

http://www.andrewcohen.org/materialism-wound/

1 Like

Hi There,

On pages, like for example this one: http://www.andrewcohen.org/listen/, with your current setup, edit the first section and set Parallax option To ON

Hope this helps.

Hi Lely,

Many thanks for your reply.

I understand how to activate the parallax effect on background images - that’s not the support question I’m seeking an answer to.

Please take a look at the blog posts on my staging site. They appear under the section entitled “Journal”, e.g. the example I posted earlier.

You’ll see that the title of the blog appears overlaid on the full width parallax image. This effect was created using Ben Ryan’s customisation method referred to in the previous thread.

What I’m trying to achieve on my pages is the same thing: to have the title of the page overlaid on the featured image for the page with the same CSS styling you see on the blog posts.

Ideally I’d like to use the same custom method used by @BenRyan.me The method uses a child theme with a customised wp-single.php and some custom CSS styling. The advantage of this method is that it allows you to use a featured image, and pull in the title text for the blog post for the overlay.

Ideally I’d like to customise the wp-page.php and add it to my child theme. Is there a way to adapt the code provided by Ben Ryan and use it for pages?

Please see the code Ben uses for his custom wp-single.php. Could the following code be adapted to create a customised wp-page.php?

<?php

// =============================================================================
// VIEWS/INTEGRITY/WP-SINGLE.PHP
// -----------------------------------------------------------------------------
// Single post output for Integrity.
// =============================================================================

$fullwidth = get_post_meta( get_the_ID(), '_x_post_layout', true );

?>

<?php get_header(); ?>

<?php global $post; ?>

<div class="benryan featured-image bg-image parallax" style="background-image:url(<?php 
the_post_thumbnail_url(full); ?>) !important;" data-x-element="section" data-x-params="
{&quot;type&quot;:&quot;image&quot;,&quot;parallax&quot;:true}";">
    <div class="x-container max width">
      <div class="caption">
        <h1 class="title h2"><?php the_title(); ?></h1>
    <?php while ( have_posts() ) : the_post(); ?>
    <?php x_integrity_entry_meta(); ?>
    <?php endwhile; ?>
      </div>
    </div>
</div> 
  <div class="x-container max width offset">
    <div class="<?php x_main_content_class(); ?>" role="main">

      <?php while ( have_posts() ) : the_post(); ?>
        <?php x_get_view( 'integrity', 'content', get_post_format() ); ?>
        <?php x_get_view( 'global', '_comments-template' ); ?>
      <?php endwhile; ?>

    </div>

    <?php if ( $fullwidth != 'on' ) : ?>
      <?php get_sidebar(); ?>
    <?php endif; ?>

  </div>

<?php get_footer(); ?>

Thanks again.

1 Like

Hello There,

Thank you for the clarifications. Please be advised that pages and posts are very different. The posts only have one layout. With pages, you are using page templates. In X, you have 14 page templates for different design layouts. If you want to have something the same as you post templates, you will have to create another one for that template.

To do that, please follow these steps:
1.) Please create a new file in your computer an insert the following code:

<?php

// =============================================================================
// TEMPLATE NAME: Fullwidth Parallax Featured Image
// -----------------------------------------------------------------------------
// A page template with fullwidth parallax featured image
// =============================================================================

?>

<?php x_get_view( x_get_stack(), 'fullwidth', 'parallax' ); ?>

2.) Save this file as fullwidth-parallax.php file and upload this to wp-content/themes/x-child/
3.) Create another file and insert the following code

<?php

// =============================================================================
// VIEWS/INTEGRITY/FULLWIDTH-PARALLAX.PHP Fullwidth Parallax Featured Image
// -----------------------------------------------------------------------------
// A page template with fullwidth parallax featured image
// =============================================================================

?>

<?php get_header(); ?>

<?php global $post; ?>

<div class="benryan featured-image bg-image parallax" style="background-image:url(<?php 
the_post_thumbnail_url(full); ?>) !important;" data-x-element="section" data-x-params="
{&quot;type&quot;:&quot;image&quot;,&quot;parallax&quot;:true}";">
    <div class="x-container max width">
      <div class="caption">
        <h1 class="title h2"><?php the_title(); ?></h1>
    <?php while ( have_posts() ) : the_post(); ?>
    <?php x_integrity_entry_meta(); ?>
    <?php endwhile; ?>
      </div>
    </div>
</div> 

  <div class="x-main full" role="main">

    <?php while ( have_posts() ) : the_post(); ?>

      <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
        <?php x_get_view( 'global', '_content', 'the-content' ); ?>
      </article>

    <?php endwhile; ?>

  </div>

<?php get_footer(); ?>

4.) Save this file as fullwidth-parallax.php and upload this file to wp-content/themes/x-child/framework/views/integrity/

To apply the page template, you will need to edit your existing pages of your site and change the page template to “Fullwidth Parallax Featured Image” template.

Please let us know how it goes.

1 Like

Awesome, it works! Many thanks @RueNel - I’m almost there.

The only thing I’d like to change is the gradient color overlay. At the moment this color styling is inerited from the CSS I applied to my full width parallax posts, meaning it is universally applied across both posts and pages.

I would like a different gradient overlay color on the page featured images - what would I need to change so that I can apply some dedicated CSS for the gradient overlay on my new full width parallax page template?

Hi there,

Should it be specific page or all page? You can try these along with your preferred gradient color

/* all pages */
.page .featured-image:after {
    bottom: 0;
    background: linear-gradient(to bottom, rgb(124, 211, 202), #0f3443);
    opacity: 0.7;
}

/* specific page with ID 221 */
.page-id-221 .featured-image:after {
    bottom: 0;
    background: linear-gradient(to bottom, rgb(124, 211, 202), #0f3443);
    opacity: 0.7;
}

And to find your page/post ID, please check this one https://theme.co/apex/forum/t/setup-how-to-locate-post-ids/59

Thanks!

1 Like

Great idea

Thank you! :slight_smile:

@RueNel, @BenRyan.me,

I wonder if either of you can throw light on the reason why Ben’s excellent Full Width Parallax customisation is not resizing properly on iPad Safari in iOS 13? This seems to only affect iPad Safari and not iPad Chrome.

As you can see, the image is very enlarged, as if the media query is not working correctly. This is happening on all my sites which have Ben’s single post template, the example given is https://trademarkfilms.co.uk.

Any help much appreciated!

Hello Michael,

Can you please clear your iPad browser’s cache? You may need to use private browsing mode and test your site again. If it displays correct in Chrome, then most probably it is a browser rendering issue.

Kindly let us know how it goes.

Hi @RueNel,

I cleared the cache in iPad Safari and then tested the site in private browsing mode as suggested. It doesn’t change the result, the site still displays as above.

Hey Michael,

Your Safari version doesn’t support background-attachment well (see https://caniuse.com/#feat=background-attachment). background-attachment is the one responsible for the parallax effect.

Since this issue is comes from a custom code, please hire a developer to make it work for old iPads.

Thanks.

My iPad Pro is running the latest version of iOS 13.3. The Safari version running on my iPad Pro is also therefore the latest version.

I see. I’ve replicated the issue in old iPad though and not on iPad Pro. With that said, this issue with the custom code got even weirder so you really need to forward this to a third-party developer.

Thank you for understanding.

UPDATE: My bad. my iPad Pro is using Safari 12. I’ve upgraded to 13 and I could see the issue. This means that this is an issue with Safari 13. We can’t fix this though as this is not a part of the theme.

I’d recommend you kindly wait for the Layout Builder feature which is coming soon. That will allow you to build a custom single post view so you might be able to use the native parallax feature of our builder.

Thanks.

Hey @christian_y,

Thanks for the clarification, I guess there’s no easy way around this at present.

iOS 13 seems to really suck. Meanwhile does this help?

Hey Michael,

Not sure if it would work but you could try it.

Thanks.

I’m a little out of my depth to be honest, I just posted it in case it might help throw some light on what is happening. I think it is a case of handing over to a more experienced developer!

Thanks for understanding, Michael.

For anyone else with this problem, here is the solution. Place this code in functions.php

add_action('wp_footer',function(){
?>
<script>
    let isIOS = /iPad|iPhone|iPod/.test(navigator.platform) || (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1);
    if(isIOS){
        jQuery('.featured-image.parallax').css('background-attachment','initial');
    }
</script>
<?php    
});