简体   繁体   English

WordPress的重力形式动态传递形式的ID

[英]Wordpress Gravity Forms Dynamic passing of id of form

I can hardcode the shortcode for Id in template but I read that this is not a good practice, my question is how to dinamicly pass Id of form so that one day when user needs a new form he can change it without calling a developer(me)? 我可以在模板中将Id的简码硬编码,但我读到这不是一个好习惯,我的问题是如何动态传递表单的Id,以便有一天用户需要新表单时,他可以更改它而无需致电开发人员(me )?

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>                 


   <?php echo do_shortcode("[gravityform id='1' title='true' description='true']"); ?>

<?php endwhile; else : ?>

将其放在(高级)自定义字段中,或仅放在内容中。

Use Advanced Custom Fields and create an Options page where the shortcode can be edited, examples are available here: 使用“高级自定义字段”并创建一个“选项”页面,可以在其中编辑短代码,此处提供示例:

https://www.advancedcustomfields.com/resources/options-page/ https://www.advancedcustomfields.com/resources/options-page/

Then in your theme you put something like the_field('contact_form, 'option'); 然后在主题中放入the_field('contact_form, 'option'); instead of the echo do_shortcode(...); 而不是echo do_shortcode(...); part you have now. 您现在拥有的部分。 Afterwards the user can edit the field and insert a new form. 之后,用户可以编辑该字段并插入新表单。

If you're already using ACF or are open to using it, you might consider this plugin which will allow the user to select from a list of Gravity Forms: 如果您已经在使用ACF或愿意使用ACF,则可以考虑使用此插件,该插件将允许用户从Gravity Forms列表中进行选择:

https://github.com/stormuk/Gravity-Forms-ACF-Field https://github.com/stormuk/Gravity-Forms-ACF-Field

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM