1
votes

I'm using Easing Slider Pro for slideshows and Advanced Custom Fields to build a custom page layout. I can't figure out why the ACF & Easing PHP only outputs the ID number of the slider I want to insert into a page, not the slider itself.

I found this old thread, which has the same problem but it's for regular ACF, not a flexible content field: Wordpress PHP within PHP -- also, the recommended ES output code has changed a bit, like slider 159 would look like:

<?php if ( function_exists( 'easingslider' ) ) { easingslider( 159 ); } ?>

Here's my code, which works fine for photos and texts:

<?php while(the_flexible_field('flex_field')): ?>
    <?php if(get_row_layout() == 'photo'): ?>
      <div class="col-md-6">
         <h2>Photos</h2>
<img src='<?php the_sub_field('photo-stack_image'); ?>' class="img-responsive" />
      <BR><BR>
<img src='<?php the_sub_field('photo-stack_image2'); ?>' class="img-responsive" />
     </div>

<?php elseif( get_row_layout() == 'text' ): ?>
    <div class="col-md-6">
      <h2>Texts</h2>
         <?php the_sub_field('text_field');?>
    </div>

<?php elseif(get_row_layout() == 'slider'): ?>
     <div class="col-md-6">
       <h2>Sliders</h2>
          <?php if ( function_exists( 'easingslider' ) ) 
            { easingslider( the_sub_field('easing_slider_shortcode') ); } ?>
     </div>
<?php endif; ?>
<?php endwhile; ?>

I've tried switching the_sub_field with get_sub_field but that doesn't even output the ID. I'm new-ish to PHP and wouldn't be surprised to learn that I missed something simple, but what? Thanks in advance!

Update: Thanks Hobo! Per your suggestions, I tested the ES function (it works), and found that both "echo get_sub_field('easing_slider_shortcode')" and "print_r(get_sub_field('easing_slider_shortcode'))" brought back just the ID number of the slider, with no additional code. I've double checked the names of the flex field, field and subfield and they're all correct.

I don't know if this helps suggests what the problem is, but I added the PHP code around the ES ID number via ACF's admin-side prepend and append feature, but it didn't echo out the code on the page.

Update Two That second try did the trick -- thanks Hobo! Here's my final code if anyone has this problem in the future:

<div class="col-md-6">
     <?php elseif(get_row_layout() == 'slider'): ?>
     <?php if ( function_exists( 'easingslider' ) ) {
         $slider_id = (int) get_sub_field('easing_slider_shortcode');
    easingslider( $slider_id );
} ?>

1
I've updated my answer based on your additional info. Like I said, I'm confused why it's not working, but there are a couple more things to try. If they don't work, and there's nothing in your PHP logs, let us know. I might have some time tomorrow (it's morning here, so that's in 24 hours) and I can download the plugins and have a look. Hopefully there's not too much difference between Easing Slider and Easing Slider Pro.Hobo

1 Answers

0
votes

First, get_sub_field() is almost certainly what you want. the_sub_field() will output a value straight away; use get_sub_field() when you want to use the value in another function.

Now you'll want to debug whether the problem's with the easingslider() function or the value returned by get_sub_field().

To check the easingslider() function, just replace the ACF function with the value it returns, eg

<div class="col-md-6">
    <h2>Sliders</h2>
    <?php if ( function_exists( 'easingslider' ) ) 
        { easingslider( 159 ); } ?>
</div>

If that looks OK, you know the problem's with the value being returned by get_sub_field(). If it doesn't look right, check you're using the right ID.

Assuming the problem's with the value returned by get_sub_field(), you'll want to check it's only returning an integer, and not (say) in integer wrapped in extra HTML (the _shortcode part of the name worries me on that front). So this time, just echo the value being returned without calling the easingslider() function, eg

<div class="col-md-6">
    <h2>Sliders</h2>
    #<?php echo get_sub_field('easing_slider_shortcode'); ?>#
</div>

Then view the generated page source (eg Ctrl-U in Chrome), and have a look at what's between the # symbols. If there's anything except the ID, check your field definition and make sure it's only a number. If there's nothing, try

<div class="col-md-6">
    <h2>Sliders</h2>
    #<?php print_r(get_sub_field('easing_slider_shortcode')); ?>#
</div>

which will give you more detail of what PHP is storing. See the print_r documentation.

If there's still nothing, check you have the right field name.

If this process doesn't help you find the problem, update your question with what you do find.

Update

Thanks for your update. I'm a little baffled why it's not working, but there are a few more things to try. I haven't used ACF's admin-side prepend and append feature, so I'm not sure whether the lack of an echoed value is a problem.

First, are there any messages or errors in your PHP logs? If there are, that might help to debug the problem.

Next, check easingslider() can take a variable as an argument. I can't see why it wouldn't, but I can't see why what you have isn't working...

<div class="col-md-6">
    <h2>Sliders</h2>
    <?php if ( function_exists( 'easingslider' ) ) {
        $slider_id = 159 ;
        easingslider( $slider_id );
    } ?>
</div>

If that works, try

<div class="col-md-6">
    <h2>Sliders</h2>
    <?php if ( function_exists( 'easingslider' ) ) {
        $slider_id = (int) get_sub_field('easing_slider_shortcode');
        easingslider( $slider_id );
    } ?>
</div>

Maybe there's a type check somewhere in the easingslider() code.