PHP中的Wordpress PHP

I am trying to achieve an outcome that combines two plugins in WordPress.

Basically, I am using Easing Slider Pro and Advanced Custom Fields. When the website owner edits a page, I want them to be able to add a slideshow by simply entering the slideshow ID into an Advanced Custom Field called 'slider'.

This is how one would normally add the PHP to display a slideshow:

<?php if ( function_exists('easingsliderpro') ) { easingsliderpro( 5 ); } ?>

The 5 is an example of a slideshow ID that can be changed.

Here is the PHP for the advanced custom field:

<?php if( get_field('slider') ): ?><?php the_field('slider'); ?><?php endif; ?>

Both of these work fine by themselves. But I want a way to combine these two pieces of code so that in the page editor the website manager only has to enter the ID of the slideshow. I don't know a lot about PHP and I am often confused by it, but this was my initial attempt:

<?php if( get_field('slider') ): ?>
<div id="sliderframe"><?php if ( function_exists('easingsliderpro') ) { easingsliderpro( <?php the_field('slider'); ?> ); } ?></div>
<?php endif; ?>

It didn't work, I am assuming because you're not allowed to have PHP code within PHP code. Is there any workaround that anyone knows that could make this achievable?

Many thanks.

Am I crazy? Can't you just:

AHA!

I think I see the confusion: the_field echoes the value out, so it gets passed to easingsliderpro() as just true, and displays the value.

You need to use a function that returns the value, so you can pass it to the next function.

In this case, it's get_field():

<?php if( get_field('slider') ): ?>
    <div id="sliderframe">
        <?php 
            if ( function_exists('easingsliderpro') ) :
                easingsliderpro( get_field('slider') );
            endif;
        ?>
    </div>
<?php endif; ?>

See more in the documentation: http://www.advancedcustomfields.com/resources/functions/get_field/

You shouldn't put php open close tags within a php open/close tag. For your code above, this is valid:

<div id="sliderframe"><?php if ( function_exists('easingsliderpro') ) { 
  easingsliderpro(the_field('slider')); 
} ?></div>