Quantcast
Channel: Question and Answer » meta-query
Viewing all articles
Browse latest Browse all 36

Meta Box Plugin – Adding field value inside echo

$
0
0

I am using Meta Box Plugin to add some custom options to my Page Edit.
I added a field to add an image background to the header which is working great. This image background has a parallax background effect.

I have the following code:

<div class="intro-header-bg"><?php $images = rwmb_meta( 'restauranttheme_hero_bg_image', 'type=image_advanced&size=full' );
foreach ( $images as $image ) {
    echo "<div data-parallax-ratio='1.1' data-direction='down' style='background-image:url({$image['url']});' />";
} ?></div>

In the code note the data-parallax-ratio=’1.1′ which adjusts the parallax speed.

I would like to add an option to Page Edit to give the user the ability to change that ratio (speed).

I can add the option to Page Edit (meta box) however I cannot seem to be able to add the string inside that code to pull in the custom value from Page Edit.

I tried the following but it is wrong:

<div class="intro-header-bg"><?php $images = rwmb_meta( 'restauranttheme_hero_bg_image', 'type=image_advanced&size=full' );
foreach ( $images as $image ) {
    echo "<div data-parallax-ratio='rwmb_meta('restauranttheme_parallax_speed' );' data-direction='down' style='background-image:url({$image['url']});' />";
} ?></div>

Can anyone help?

I am learning PHP so please excuse my ignorance.

P.S. – This is the the array for both fields:

array(
            // Field name - Will be used as label
            'name'  => __( 'Hero Background Image', 'restauranttheme' ),
            // Field ID, i.e. the meta key
            'id'    => "{$prefix}hero_bg_image",
            // Field description (optional)
            'desc'  => __( 'Hero section background image', 'restauranttheme' ),
            'type'  => 'image_advanced',
            'max_file_uploads' => 1,
        ),

        array(
            // Field name - Will be used as label
            'name'  => __( 'Hero Parallax Speed', 'restauranttheme' ),
            // Field ID, i.e. the meta key
            'id'    => "{$prefix}hero_parallax_speed",
            // Field description (optional)
            'desc'  => __( 'Hero section background image paralalx speed. Default is 1.1. Recommended range is from 1 to 1.5', 'restauranttheme' ),
            'type'  => 'text',
            'std'  => '1.1',
        ),

Thanks for your time.


Viewing all articles
Browse latest Browse all 36

Trending Articles