【问题标题】:how to get field values from database in template page Advanced Custom Fields - wordpress如何在模板页面高级自定义字段中从数据库中获取字段值 - wordpress
【发布时间】:2016-06-13 16:19:31
【问题描述】:

我已经安装了一个高级自定义字段插件来在帖子中上传音频和图像文件。每个帖子包含 5 个字段

带有自定义字段的新帖子

我可以发布帖子,但我不知道如何检索 wordpress 模板页面中的每个字段

帖子字段

【问题讨论】:

    标签: php html mysql wordpress advanced-custom-fields


    【解决方案1】:

    只需使用模板文件中的字段名称调用此函数

    <?php
    while ( have_posts() ): the_post();
            // Display post
            if ( have_posts() ):?> 
          <?php echo  the_field('slider_name');?>
         <?php echo   the_field('slider_description');
    
     endif;
    endwhile;
    ?>
    

    【讨论】:

    • 请添加一些解释。目前,您的回答被标记为“低质量”,可能会被删除。
    【解决方案2】:

    你可以这样做

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
        <h1><?php the_field('main_content_heading'); ?></h1>
    <?php endwhile; endif; ?>
    

    在循环中,使用 the_field 方法输出自定义字段。

    更多详情请看这里:http://www.advancedcustomfields.com/resources/code-examples/

    【讨论】:

      猜你喜欢
      • 2014-02-06
      • 1970-01-01
      • 2015-05-27
      • 1970-01-01
      • 2016-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-01
      相关资源
      最近更新 更多