From dfe7c57da3b4055afd4f3f96a8032ce304ab169e Mon Sep 17 00:00:00 2001 From: danpros Date: Sat, 24 Feb 2024 10:02:52 +0700 Subject: [PATCH] Save processing power --- system/admin/views/main.html.php | 2 +- system/admin/views/popular-posts.html.php | 2 +- system/includes/functions.php | 272 ++++++++++++++++++------------ 3 files changed, 169 insertions(+), 107 deletions(-) diff --git a/system/admin/views/main.html.php b/system/admin/views/main.html.php index 6456848..aff6740 100644 --- a/system/admin/views/main.html.php +++ b/system/admin/views/main.html.php @@ -6,7 +6,7 @@ '; echo '' . i18n('Title') . '' . i18n('Published') . ''; diff --git a/system/admin/views/popular-posts.html.php b/system/admin/views/popular-posts.html.php index 6877aba..9c0078c 100644 --- a/system/admin/views/popular-posts.html.php +++ b/system/admin/views/popular-posts.html.php @@ -22,7 +22,7 @@ title ?> date) ?> - views ?> + slug); ?> author ?> category);?> tag ?> diff --git a/system/includes/functions.php b/system/includes/functions.php index 8bee46f..e058e1f 100644 --- a/system/includes/functions.php +++ b/system/includes/functions.php @@ -1478,7 +1478,7 @@ function recent_posts($custom = null, $count = null) if (file_exists($filename)) { $posts = unserialize(file_get_contents($filename)); - if (count($posts) != $count) { + if (count($posts) < $count) { $posts = get_posts(null, 1, $count); $tmp = serialize($posts); file_put_contents($filename, print_r($tmp, true), LOCK_EX); @@ -1490,11 +1490,21 @@ function recent_posts($custom = null, $count = null) } if (!empty($custom)) { - return $posts; + $arr = array(); + $i = 1; + foreach ($posts as $post) { + $arr[] = $post; + if ($i++ >= $count) + break; + } + return $arr; } else { + $i = 1; $recent .= '