doupeng6890 2013-11-08 21:33
浏览 17
已采纳

在另一个模板标记里面的Wordpress模板标记

Here's a fun one. I'm using advanced custom fields inside of a template to pull a field called Applications with the following code.

 the_field('applications');

The problem is that this won't pull the actual content without the page ID along with it, for example:

 the_field('applications','42');

where the page ID is 42.

What I would like to do is use another template tag to pull the existing page ID with something like this in place of the 42, so that it will content specific to that page:

 the_ID();

Which, in a perfect world would look like so:

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

This is obviously ridiculous and doesn't work, but I don't know what I need to do to get this to actually work.

Thanks!

  • 写回答

1条回答 默认 最新

  • duancuisan2503 2013-11-08 21:36
    关注

    the_ID() will automatically echo whatever is returned, whereas get_the_ID() will return that value so that it can be stored in a variable, or passed as an argument (which is the deal in this case).

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

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大