add files inc
This commit is contained in:
43
inc/popular-json.php
Normal file
43
inc/popular-json.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
$json_path = CACHED_TEMPLATE.'json';
|
||||
|
||||
$ids = array_map(
|
||||
function ($item) { return $item->id; },
|
||||
json_decode(get_option("ppp_options") ?: '[]')
|
||||
);
|
||||
|
||||
$posts = get_posts([
|
||||
"post_type" => ["anew", "yellow"],
|
||||
"post_status" => "publish",
|
||||
"posts_per_page" => 20,
|
||||
"ignore_sticky_posts" => true,
|
||||
"post__in" => $ids,
|
||||
"orderby" => "post__in",
|
||||
"meta_query" => [[
|
||||
"key" => "_thumbnail_id",
|
||||
"compare" => "EXISTS"
|
||||
]]
|
||||
]);
|
||||
|
||||
$data = array_map(function($post) {
|
||||
$thumbnail = get_the_post_thumbnail_url($post->ID, 'thumb-264');
|
||||
|
||||
return [
|
||||
'id' => $post->ID,
|
||||
'title' => get_the_title($post->ID),
|
||||
'link' => get_permalink($post->ID),
|
||||
'thumbnail' => $thumbnail ?: wp_get_attachment_image_url(1357368, 'thumb-264'),
|
||||
'alt' => get_the_title($post->ID)
|
||||
];
|
||||
|
||||
}, $posts);
|
||||
|
||||
// Создаем директорию если не существует
|
||||
if (!file_exists($json_path)) {
|
||||
wp_mkdir_p($json_path);
|
||||
}
|
||||
|
||||
$json_file = $json_path.'popular';
|
||||
|
||||
file_put_contents($json_file, json_encode($data, JSON_UNESCAPED_UNICODE));
|
||||
Reference in New Issue
Block a user