add support menu color in graphql
This commit is contained in:
@@ -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 ) {
|
||||||
|
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
Reference in New Issue
Block a user