如何在自定义功能中呈现灵活的内容布局?

时间:2018-09-25 07:48:56

标签: php wordpress

我实现了“灵活内容”自定义字段,并且根据模板页面中的顺序呈现了内容:

<div class="container">
    <?php

    if( have_rows('content') ):
        while ( have_rows('content') ) : the_row();?>

            <?php switch(get_row_layout()) :

                case 'text_field': require_once THEME_DIRECTORY . '/pages/text_field.php'; break;
                case 'lead_text' : require_once THEME_DIRECTORY . '/pages/lead_text.php'; break;
                //case 'newsletter_form' : require_once THEME_DIRECTORY . '/pages/newsletter_form.php'; break;
                ?>
                <form id="testForm">
                    <?php
                    case 'newsletter_form_one' : require_once THEME_DIRECTORY . '/pages/forms/form-one.php'; break;
                    case 'newsletter_form_two' : require_once THEME_DIRECTORY . '/pages/forms/form-two.php'; break;
                    case 'newsletter_form_three' : require_once THEME_DIRECTORY . '/pages/forms/form-three.php'; break;
                    case 'newsletter_form_four' : require_once THEME_DIRECTORY . '/pages/forms/form-four.php'; break;?>
                </form>
                <?php
                case 'pool' : require_once THEME_DIRECTORY . '/pages/pool.php'; break;
                case 'studien_list' : require_once THEME_DIRECTORY . '/pages/studien.php'; break;
              //  case 'social_hub_content' : include THEME_DIRECTORY . '/pages/social-hub.php'; break;
                default: break;

            endswitch; endwhile; endif;
    ?>
    <?php get_footer()?>
</div>

但是我需要在functions.php文件的自定义函数中调用其中之一:

function getFormContent()
{
    require_once THEME_DIRECTORY . '/pages/forms/form-two.php';
}

结果呈现为空类且没有属性...可以像在模板页面中那样调用该布局吗?

0 个答案:

没有答案