$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>theme development - How do I create a custom partialtemplate?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

theme development - How do I create a custom partialtemplate?

matteradmin8PV0评论

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 badges
Add a comment  | 

1 Answer 1

Reset to default 2

The 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' );
Post a comment

comment list (0)

  1. No comments so far