dongying3830 2016-08-09 11:10
浏览 135

从acf选择字段加载选定的内容

On wordpress and ACF,
I am searching for a way to load different <div> (one OR the other, not both)
based on the choosen content from the ACF « select » field (named « type_of_page ») when the page load.

I have two type of selector « actual » OR « archive »
that have to load two <div> « #now » OR « #before »

    <?php

if(get_field('type_of_page') == "archive")
{
    //...
}

?>

<div id="now">NOW</div>
<div id="before">BEFORE</div>

How sould I release that, without loading both ?

  • 写回答

1条回答 默认 最新

  • dpgvdfg321041670 2017-02-21 11:42
    关注

    You've pretty much got it:

    <?php if( get_field( 'key' ) == 'value' ) : ?>
      <div id="content-a"></div>
    <?php else : ?>
      <div id="content-b"></div>
    <?php endif; ?>
    

    If you are worried that content-b will load but be hidden in cases where content-a is desired, check the source code after viewing the page in a browser. You will see that content-b cannot be loaded if content-a is loaded (and vice-versa) using this logic.

    评论
    编辑
    预览

    报告相同问题?

    手机看
    程序员都在用的中文IT技术交流社区

    程序员都在用的中文IT技术交流社区

    专业的中文 IT 技术社区,与千万技术人共成长

    专业的中文 IT 技术社区,与千万技术人共成长

    关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

    关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

    客服 返回
    顶部