From dd365de9ff7aa86cbe64842f159aa24395f5a6f1 Mon Sep 17 00:00:00 2001 From: Kr1PtunZ Date: Thu, 30 May 2024 18:11:59 +0500 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=BD=D0=B0=20=D0=BE=D1=82=D0=B4=D0=B5=D0=BB=D1=8C=D0=BD?= =?UTF-8?q?=D0=B0=D1=8F=20=D1=81=D1=82=D1=80=D0=B0=D0=BD=D0=B8=D1=86=D1=8B?= =?UTF-8?q?=20=D0=B4=D0=BB=D1=8F=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../themes/simple-theme/api-template.php | 5 +++++ wp-content/themes/simple-theme/functions.php | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 wp-content/themes/simple-theme/api-template.php diff --git a/wp-content/themes/simple-theme/api-template.php b/wp-content/themes/simple-theme/api-template.php new file mode 100644 index 0000000..e57e9f9 --- /dev/null +++ b/wp-content/themes/simple-theme/api-template.php @@ -0,0 +1,5 @@ +- + */ diff --git a/wp-content/themes/simple-theme/functions.php b/wp-content/themes/simple-theme/functions.php index 70c2f5f..05234d2 100644 --- a/wp-content/themes/simple-theme/functions.php +++ b/wp-content/themes/simple-theme/functions.php @@ -2,6 +2,25 @@ 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) function gV($gv)