2016-10-05 85 views
0

如何在模板中聲明區域以在其他模板文件中使用?模板中的多個塊

基本上,我想要我的模板中的2個區域用於containercontainer-fluid類型的引導程序。

現在我宣佈一個div在header.php文件container類,並關閉在footer.php。所以一切都在div是container DIV中。

Twig我可以使用下面的語法:

<div class="container"> 

{% block container %} 

{% endblock %} 

</div> 

<div class="container-fluid"> 

    {% block container-fluid %} 

    {% endblock %} 

</div> 

和子模板只是把內容塊

{% block container-fluid %} 

// my content 

{%endblock %} 
+0

聽起來[get_template_part()](HTTPS ://developer.wordpress.org/reference /功能/ get_template_part /)。 –

回答

0

兒童主題 使用loop.php假設主題文件夾是wp-content/themes,父主題是twentyten,子主題是twentytenchild,那麼下面的代碼 -

<?php get_template_part('loop', 'index'); ?> 

會做PHP的require()用於在這些存在的第一個文件,在這個優先級:

的wp-content /主題/ twentytenchild /環路的index.php

的wp-content /主題/twentyten/loop-index.php

可溼性粉劑內容/主題/ twentytenchild/loop.php

可溼性粉劑內容/主題/ twentyten/loop.php