Compare commits
2 Commits
35d1270a4b
...
793f6914f0
Author | SHA1 | Date | |
---|---|---|---|
793f6914f0 | |||
dd365de9ff |
5
wp-content/themes/simple-theme/api-template.php
Normal file
5
wp-content/themes/simple-theme/api-template.php
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* Template name: api-template
|
||||||
|
* description: >-
|
||||||
|
*/
|
@ -2,6 +2,25 @@
|
|||||||
|
|
||||||
require get_theme_file_path('/api-posts/api-posts.php');
|
require get_theme_file_path('/api-posts/api-posts.php');
|
||||||
|
|
||||||
|
// Add rewrite rule
|
||||||
|
add_action('init', function () {
|
||||||
|
add_rewrite_rule('api-template/?$', 'index.php?static_template=api-template', 'top');
|
||||||
|
flush_rewrite_rules(); // Only needed for local development
|
||||||
|
});
|
||||||
|
|
||||||
|
// Whitelist the custom query var
|
||||||
|
add_filter('query_vars', function($queryVars) {
|
||||||
|
$queryVars[] = 'static_template';
|
||||||
|
return $queryVars;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Conditionally render the custom template
|
||||||
|
add_action('template_include', function($template) {
|
||||||
|
if (get_query_var('static_template') == 'api-template') {
|
||||||
|
return get_template_directory(). '/api-template.php';
|
||||||
|
}
|
||||||
|
return $template;
|
||||||
|
});
|
||||||
|
|
||||||
// ? get variables (globally)
|
// ? get variables (globally)
|
||||||
function gV($gv)
|
function gV($gv)
|
||||||
|
Loading…
Reference in New Issue
Block a user