Compare commits

..

2 Commits

Author SHA1 Message Date
Profile Profile
ddf44fbfad add graphql types 2026-01-25 21:14:24 +03:00
Profile Profile
9ed823e0af add support menu color in graphql 2026-01-25 01:02:17 +03:00
3 changed files with 19 additions and 11 deletions

View File

@@ -9,25 +9,30 @@
* @param int $expire Время жизни кеша в секундах * @param int $expire Время жизни кеша в секундах
* @return void * @return void
*/ */
function cached_get_template_part( $template, $name = null, $data = [] ) { function cached_get_template_part( $template, $name = null, $data = [], $ttl = 3600 ) {
$fcache = CACHED_TEMPLATE.$template.'.html'; $fcache = CACHED_TEMPLATE.$template.'.html';
// Проверяем существование файла и его время жизни
if ( file_exists($fcache) ){ if ( file_exists($fcache) ){
echo file_get_contents($fcache); $cache_time = filemtime($fcache);
return true; $current_time = time();
// Если кеш не истек, отдаем его
if ( ($current_time - $cache_time) < $ttl ) {
echo file_get_contents($fcache);
return true;
}
} }
$file_directory = dirname($fcache); $file_directory = dirname($fcache);
ob_start(); ob_start();
get_template_part($template, $name, $data ); get_template_part($template, $name, $data );
$content = ob_get_clean(); $content = ob_get_clean();
echo $content; echo $content;
if (!file_exists($file_directory)) { if (!file_exists($file_directory)) {
if (!wp_mkdir_p($file_directory)) { if (!wp_mkdir_p($file_directory)) {
error_log('Не удалось создать директорию: ' . $file_directory); error_log('Не удалось создать директорию: ' . $file_directory);
@@ -41,9 +46,9 @@ function cached_get_template_part( $template, $name = null, $data = [] ) {
} }
return true; return true;
} }
// Функция очистки кеша // Функция очистки кеша
function clear_template_cache ( $template ) { function clear_template_cache ( $template ) {

View File

@@ -14,6 +14,9 @@ require "inc/meta_keywords.php";
require "inc/journal_issue.php"; //номера журналов require "inc/journal_issue.php"; //номера журналов
require "inc/rank-description.php"; require "inc/rank-description.php";
//utils
require "utils/acf-category.php";
//scheduler //scheduler
require "inc/schedule_async_post_processing.php"; require "inc/schedule_async_post_processing.php";
if ( defined( 'WP_CLI' ) && WP_CLI ) { if ( defined( 'WP_CLI' ) && WP_CLI ) {

View File

@@ -2,16 +2,16 @@
<?php //get_template_part("template-parts/home/news"); <?php //get_template_part("template-parts/home/news");
cached_get_template_part( 'template-parts/home/news' );?> cached_get_template_part( 'template-parts/home/news' );?>
<div class="col-12 col-md-8 col-xl-6 float-left"> <div class="col-12 col-md-8 col-xl-6 float-left">
<?php //get_template_part("template-parts/home/main-item"); <?php get_template_part("template-parts/home/main-item");
cached_get_template_part( 'template-parts/home/main-item' ); //cached_get_template_part( 'template-parts/home/main-item' );
?> ?>
<?php //get_template_part("template-parts/home/colon-item"); <?php get_template_part("template-parts/home/colon-item");
cached_get_template_part( 'template-parts/home/colon-item' ); //cached_get_template_part( 'template-parts/home/colon-item' );
?> ?>
</div> </div>