dongsetan3216 2014-04-11 03:19
浏览 44
已采纳

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.

  • 写回答

2条回答 默认 最新

  • down2323 2014-04-11 03:26
    关注

    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/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 各位请问平行检验趋势图这样要怎么调整?说标准差差异太大了
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 wpf界面一直接收PLC给过来的信号,导致UI界面操作起来会卡顿
  • ¥15 init i2c:2 freq:100000[MAIXPY]: find ov2640[MAIXPY]: find ov sensor是main文件哪里有问题吗
  • ¥15 运动想象脑电信号数据集.vhdr
  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab