admin管理员组文章数量:1130349
I have created an sign up form and placed it in my header:
<div>
<h5 class="myapp-sign-up-text">Sign up for updates</h5>
<form class="myapp-email-form">
<input type="text" name="email" placeholder="Your email address" class="myapp-subscription-input" />
<input type="submit" value="Subscribe" class="myapp-subscription-submit" />
</form>
</div>
I would like to use the same code for my footer. Is there a DRY way of putting this into a partial and loading it using a PHP function?
I have created an sign up form and placed it in my header:
<div>
<h5 class="myapp-sign-up-text">Sign up for updates</h5>
<form class="myapp-email-form">
<input type="text" name="email" placeholder="Your email address" class="myapp-subscription-input" />
<input type="submit" value="Subscribe" class="myapp-subscription-submit" />
</form>
</div>
I would like to use the same code for my footer. Is there a DRY way of putting this into a partial and loading it using a PHP function?
Share Improve this question edited Dec 5, 2018 at 21:56 Krzysiek Dróżdż 25.6k9 gold badges53 silver badges74 bronze badges asked Dec 5, 2018 at 21:33 bigpotatobigpotato 3352 gold badges6 silver badges17 bronze badges1 Answer
Reset to default 2The thing you're searching for is get_template_part function.
So let's say you put your form in file called part-form-signup.php. Then you can easily include that partial template anywhere using:
get_template_part( 'part-form-signup' );
I have created an sign up form and placed it in my header:
<div>
<h5 class="myapp-sign-up-text">Sign up for updates</h5>
<form class="myapp-email-form">
<input type="text" name="email" placeholder="Your email address" class="myapp-subscription-input" />
<input type="submit" value="Subscribe" class="myapp-subscription-submit" />
</form>
</div>
I would like to use the same code for my footer. Is there a DRY way of putting this into a partial and loading it using a PHP function?
I have created an sign up form and placed it in my header:
<div>
<h5 class="myapp-sign-up-text">Sign up for updates</h5>
<form class="myapp-email-form">
<input type="text" name="email" placeholder="Your email address" class="myapp-subscription-input" />
<input type="submit" value="Subscribe" class="myapp-subscription-submit" />
</form>
</div>
I would like to use the same code for my footer. Is there a DRY way of putting this into a partial and loading it using a PHP function?
Share Improve this question edited Dec 5, 2018 at 21:56 Krzysiek Dróżdż 25.6k9 gold badges53 silver badges74 bronze badges asked Dec 5, 2018 at 21:33 bigpotatobigpotato 3352 gold badges6 silver badges17 bronze badges1 Answer
Reset to default 2The thing you're searching for is get_template_part function.
So let's say you put your form in file called part-form-signup.php. Then you can easily include that partial template anywhere using:
get_template_part( 'part-form-signup' );
本文标签: theme developmentHow do I create a custom partialtemplate
版权声明:本文标题:theme development - How do I create a custom partialtemplate? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749125240a2319668.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论