4

在我的项目中,我需要在前端显示自定义帖子字段表单,所以我已经安装了 ACF 并创建了自定义字段,现在我的问题是如何将这些字段与 HTML 一起呈现????我使用了 get_fields() 函数,但它仍然不会显示任何 HTML 代码。

4

5 回答 5

4

如果要显示帖子中的字段,则必须将代码放在“single.php”的循环中,假设您使用的是标准帖子类型。

此代码仅检索该字段,它不会显示任何内容,它用于将值存储在变量中:

get_field('field-name');

要使字段显示在模板中,您必须使用以下内容:

the_field('field-name');

您还可以在存档模板中插入代码或查询您用来显示帖子的帖子。

这也可行:

echo get_field('field-name')

或者

$myfield = get_field('field-name');
echo $myfield;
于 2014-11-09T02:48:50.790 回答
1

您可以使用 ACF 前端显示插件: https ://wordpress.org/plugins/acf-frontend-display

在帖子或页面编辑中选中“显示在前面”。

如果您想添加一些操作,请尝试使用表单操作插件: https ://wordpress.org/plugins/forms-actions/

于 2015-03-30T10:43:49.327 回答
1

将该代码添加到您的模板中:

<?php
/**
 * Template Name: Resume Build
 *
 * @package Betheme
 * @author Muffin Group
 */
?>
<?php
/**
 * The main template file.
 *
 * @package Betheme
 * @author Muffin group
 * @link http://muffingroup.com
 */
acf_form_head();
get_header();


?>


<!-- #Content -->
<div id="Content">
    <div class="content_wrapper clearfix">

        <!-- .sections_group -->
        <div class="sections_group">

            <div id="content">

    <?php

    acf_form(array(
        'post_id'       => 'new_post',
        'post_title'    => true,
        'post_content'  => false,
        'new_post'      => array(
            'post_type'     => 'resume',
            'post_status'   => 'publish'
        )
    ));

    ?>

</div>



        </div>  

        <!-- .four-columns - sidebar -->
        <?php get_sidebar( 'blog' ); ?>

    </div>
</div>

<?php get_footer();

// Omit Closing PHP Tags
于 2018-03-06T10:47:18.827 回答
0

看看这个文档...

您可以使用以下功能添加字段或完整表单,

$options = array(
    'post_id' => $post->ID, // post id to get field groups from and save data to
    'field_groups' => array(), // this will find the field groups for this post (post ID's of the acf post objects)
    'form' => true, // set this to false to prevent the <form> tag from being created
    'form_attributes' => array( // attributes will be added to the form element
        'id' => 'post',
        'class' => '',
        'action' => '',
        'method' => 'post',
    ),
    'return' => add_query_arg( 'updated', 'true', get_permalink() ), // return url
    'html_before_fields' => '', // html inside form before fields
    'html_after_fields' => '', // html inside form after fields
    'submit_value' => 'Update', // value for submit field
    'updated_message' => 'Post updated.', // default updated message. Can be false to show no message
);
acf_form( $options );

希望对你有帮助...

于 2014-02-20T05:37:43.513 回答
0

一切都在该文件中解释

另外,这里有一个功能可以帮助您

于 2015-05-18T14:43:31.423 回答