【问题标题】:Wordpress template tag inside of a another template tag另一个模板标签内的 Wordpress 模板标签
【发布时间】:2013-11-21 01:02:27
【问题描述】:

这是一个有趣的。我正在使用模板内的高级自定义字段来使用以下代码提取名为 Applications 的字段。

 the_field('applications');

问题是这不会在没有页面ID的情况下提取实际内容,例如:

 the_field('applications','42');

其中页面 ID 为 42。

我想做的是使用另一个模板标签来提取现有的页面 ID,用类似这样的东西代替 42,这样它就会包含特定于该页面的内容:

 the_ID();

在一个完美的世界中应该是这样的:

 the_field('applications','the_ID();');

这显然很荒谬并且不起作用,但我不知道我需要做什么才能让它真正起作用。

谢谢!

【问题讨论】:

    标签: php wordpress templatetags advanced-custom-fields


    【解决方案1】:

    the_ID() 将自动回显返回的任何内容,而 get_the_ID() 将返回该值,以便将其存储在变量中,或作为参数传递(在本例中就是这样)。

    <?php the_field('applications',get_the_ID()); ?>
    

    http://codex.wordpress.org/Function_Reference/get_the_ID

    【讨论】:

    • 做到了!非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-07-25
    • 2014-04-03
    • 2016-08-27
    • 2011-02-09
    • 1970-01-01
    • 2016-10-22
    • 2014-03-20
    相关资源
    最近更新 更多