65 lines
1.6 KiB
PHP
65 lines
1.6 KiB
PHP
<?php
|
|
/**
|
|
* Resource Related
|
|
*
|
|
* 单篇资源页底部的「相关资源」区块。
|
|
* 取同分类下其它资源(post + _aksrt_is_resource = 1,兼容旧 aksrt_resource CPT),按下载量倒序。
|
|
*
|
|
* @package AKSRT
|
|
*/
|
|
|
|
defined('ABSPATH') || exit;
|
|
|
|
$current_id = get_the_ID();
|
|
$cat_ids = wp_get_post_categories($current_id, ['fields' => 'ids']);
|
|
if (empty($cat_ids)) return;
|
|
|
|
$post_types = function_exists('aksrt_resource_post_types') ? aksrt_resource_post_types() : ['post'];
|
|
|
|
$args = [
|
|
'post_type' => $post_types,
|
|
'posts_per_page' => 6,
|
|
'post__not_in' => [$current_id],
|
|
'category__in' => array_map('intval', $cat_ids),
|
|
'meta_key' => '_aksrt_res_download_count',
|
|
'orderby' => 'meta_value_num',
|
|
'order' => 'DESC',
|
|
'no_found_rows' => true,
|
|
];
|
|
if (!post_type_exists('aksrt_resource')) {
|
|
$args['meta_query'] = [
|
|
'relation' => 'AND',
|
|
[
|
|
'key' => '_aksrt_is_resource',
|
|
'value' => '1',
|
|
'compare' => '=',
|
|
],
|
|
];
|
|
}
|
|
|
|
$query = new WP_Query($args);
|
|
|
|
if (!$query->have_posts()) {
|
|
wp_reset_postdata();
|
|
return;
|
|
}
|
|
?>
|
|
|
|
<section class="resource-related" aria-label="<?php esc_attr_e('相关资源', 'aksrt'); ?>">
|
|
<header class="resource-related__header">
|
|
<h2 class="resource-related__title"><?php esc_html_e('相关资源', 'aksrt'); ?></h2>
|
|
</header>
|
|
|
|
<div class="post-grid post-grid--grid-cms resource-related__grid">
|
|
<?php
|
|
set_query_var('aksrt_post_card_layout', 'grid-cms');
|
|
while ($query->have_posts()) {
|
|
$query->the_post();
|
|
get_template_part('templates/parts/content', 'post-card');
|
|
}
|
|
set_query_var('aksrt_post_card_layout', '');
|
|
wp_reset_postdata();
|
|
?>
|
|
</div>
|
|
</section>
|