【问题标题】:Display ACF on blog archive page在博客存档页面上显示 ACF
【发布时间】:2020-06-23 13:58:12
【问题描述】:

我需要在博客存档页面上显示一些额外的信息,但无法对其进行编码,因为其他人必须能够编辑这些信息。

我在此页面上添加了一些自定义字段,但无法在实际页面上显示它们。 有什么办法解决吗?

我的代码:

<div class="save_the_date">
    <?php
    if( have_rows('actiedagen') ):
        while ( have_rows('actiedagen') ) : the_row();
            the_sub_field('actiedagen_titel');
            the_sub_field('actiedagen_datum');
            the_sub_field('actiedagen_locatie');
        endwhile;
    else :

    endif;
    ?>
</div>

【问题讨论】:

    标签: php wordpress advanced-custom-fields acfpro


    【解决方案1】:

    您可以添加一个选项页面来编辑这些字段:

    if (function_exists('acf_add_options_page')) {
    
        acf_add_options_page(array(
            'page_title'     => 'Theme General Settings',
            'menu_title'    => 'Theme Settings',
            'menu_slug'     => 'theme-general-settings',
            'capability'    => 'edit_posts',
            'redirect'        => false
        ));
    }
    

    然后在此选项页面上显示此字段组。

    至于显示值,您需要像这样添加第二个参数“option”:

        <?php
        if( have_rows('actiedagen', 'option') ):
            while ( have_rows('actiedagen', 'option') ) : the_row();
                the_sub_field('actiedagen_titel'); // no need to add option here
                the_sub_field('actiedagen_datum');
                the_sub_field('actiedagen_locatie');
            endwhile;
        else :
    
        endif;
        ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-07-26
      • 1970-01-01
      • 1970-01-01
      • 2019-01-26
      • 1970-01-01
      • 2019-05-17
      • 1970-01-01
      相关资源
      最近更新 更多