WordPress高级自定义字段插件+ Twig模板 [英] Wordpress Advanced Custom Field Plugin + Twig template

查看:212
本文介绍了WordPress高级自定义字段插件+ Twig模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用模板 Realia 。该主题基于Twig文件,这是我的问题。我有一个前端提交,我们可以在其中添加一个自定义帖子(一个property)。我想向此表单添加一个自定义字段。获取并显示该字段的代码已经制作成功,因为它位于php文件中;

I'm creating a real estate website with the template Realia. This theme is based on Twig files and here's my problem. I have a front end submission where we can add a custom post ( a property ). I want to add a custom field to this form. The code which get and display the field is made and work because it is in a php file ;

<?php acf_form_head(); ?>

<?php acf_form( array(
    'field_groups' => array(1943),
    'form'  => false,
) ); ?>

但是现在我要保存字段数据,并且添加我的财产按钮在

But now I want to save the data of my field and the button "Add my property" is in a Twig file..

这是按钮代码

      <div class="form-actions">
            {% set value = wp.__('Save', 'aviators') %}
            <input type="submit" class="btn btn-primary" value="{{ value }}">
        </div>
    {% endif %} 

</form>

根据此文档,acf代码为 acf_form_head(),但我不知道如何将其放入我的代码。我尝试 {{acf_form_head()}} {{wp.acf_form_head()}} 和其他句子什么都行不通...我试图找到此php文件上的保存功能,但我没有

According to this documentation , the acf code is acf_form_head() but I dunno how to put it in my code. I try {{ acf_form_head() }}, {{ wp.acf_form_head() }} and some other sentence but nothing works... I tried to to find the "save" function which is on this php file but I don't know to edit it..

请,有人可以帮我吗?

请先谢谢

Jennifer O。

Jennifer O.

推荐答案

据我所知wp-realia主题。

As far as i know wp-realia theme.

{{}}

这些标签是用于将某些内容输出到浏览器或调用方法。
在调用任何功能 wp之前添加 wp。。意味着该功能是用户定义的或核心功能。如果您调用不带 wp。前缀的函数,则意味着您正在调用树枝模板函数。

These tags are used for outputting some thing to browser or calling methods. add wp. before calling any function wp. means that this functions is user defined or core function. if you call function without wp. prefix it means you are calling twig template function.

{%%}

这些标记用于调用核心树枝函数,例如 {%if my_var%}

These tag are used for calling core twig functions eg {% if my_var %}.

对于您的情况,您想在标头中调用acf_form_head()函数在标头中打印css / js和必要的文件,以便可以在realia / head标签中的templates / helpers / header.twig文件,例如:

For your scenario you want to call acf_form_head() function in header to print css/js and necessary files in the header so you can make a block in the realia/templates/helpers/header.twig file in head tag eg:

{%block header_block%} {%endblock%}

然后在您的自定义树枝模板文件引用中阻止并放置您的内容:

then in your custom twig template file reference that block and put your content in it:

{# we tell our custom template to extends from layout.twig #} 
{% extends 'layout.twig' %}

{# Add acf_form_head() function in our header block #} 
{% block header_block %}
    {{ wp.acf_form_head() }}
{% endblock %}

{# add this content to our content block which is define in layout.twig file #} 
{% block content %}
    {% if wp.have_posts() %}
        {% for post in posts %}
            {{ wp_query.the_post() }}
            My custom field: {{ wp.the_field('my_custom_field') }}
            {{ wp.acf_form() }}
        {% endfor %}
    {% endif %}
{% endblock %}

希望它会对您有所帮助。

Hope it will help you.

这篇关于WordPress高级自定义字段插件+ Twig模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆