'download_category', 'hide_empty' => false, )); // 如果没有分类,创建默认分类 if (empty($categories) || is_wp_error($categories)) { $categories = array(); } // 获取当前页码 $current_page = max(1, get_query_var('paged', 1)); // 根据是否启用分页决定获取数据的方式 if ($enable_pagination) { // 启用分页时的数据获取 $all_downloads_args = array( 'post_type' => 'download_center', 'post_status' => 'publish', 'posts_per_page' => $posts_per_page, 'paged' => $current_page, 'orderby' => $order_by, 'order' => $order, ); $all_downloads_query = new WP_Query($all_downloads_args); $all_downloads = $all_downloads_query->posts; // 按分类获取下载项目(分页) $downloads_by_category = array(); $category_queries = array(); foreach ($categories as $category) { $category_downloads_args = array( 'post_type' => 'download_center', 'post_status' => 'publish', 'posts_per_page' => $posts_per_page, 'paged' => $current_page, 'orderby' => $order_by, 'order' => $order, 'tax_query' => array( array( 'taxonomy' => 'download_category', 'field' => 'term_id', 'terms' => $category->term_id, ), ), ); $category_query = new WP_Query($category_downloads_args); $downloads_by_category[$category->term_id] = $category_query->posts; $category_queries[$category->term_id] = $category_query; } } else { // 未启用分页时的数据获取(原有逻辑) $all_downloads_args = array( 'post_type' => 'download_center', 'post_status' => 'publish', 'posts_per_page' => $posts_per_category, 'orderby' => $order_by, 'order' => $order, ); $all_downloads = get_posts($all_downloads_args); // 按分类获取下载项目 $downloads_by_category = array(); foreach ($categories as $category) { $category_downloads_args = array( 'post_type' => 'download_center', 'post_status' => 'publish', 'posts_per_page' => $posts_per_category, 'orderby' => $order_by, 'order' => $order, 'tax_query' => array( array( 'taxonomy' => 'download_category', 'field' => 'term_id', 'terms' => $category->term_id, ), ), ); $downloads_by_category[$category->term_id] = get_posts($category_downloads_args); } } // 默认图片路径 $default_image = get_template_directory_uri() . '/assets/images/PDF-IMG.webp'; $download_icon = get_template_directory_uri() . '/assets/images/PDF-ICON.svg'; ?>

term_id])): ?>
ID, '_download_url', true); $file_size = get_post_meta($download->ID, '_file_size', true); $file_type = get_post_meta($download->ID, '_file_type', true); $featured_image = get_the_post_thumbnail_url($download->ID, 'full'); $image_url = $featured_image ? $featured_image : $default_image; // 如果没有设置下载链接,使用特色图像作为下载链接 if (empty($download_url) && $featured_image) { $download_url = $featured_image; } ?>
<?php echo esc_attr($download->post_title); ?>

post_title); ?>

post_excerpt)): ?>

post_excerpt); ?>

Download Download
term_id])): ?>
term_id] as $download): ?> ID, '_download_url', true); $file_size = get_post_meta($download->ID, '_file_size', true); $file_type = get_post_meta($download->ID, '_file_type', true); $featured_image = get_the_post_thumbnail_url($download->ID, 'full'); $image_url = $featured_image ? $featured_image : $default_image; // 如果没有设置下载链接,使用特色图像作为下载链接 if (empty($download_url) && $featured_image) { $download_url = $featured_image; } ?>
<?php echo esc_attr($download->post_title); ?>

post_title); ?>

post_excerpt)): ?>

post_excerpt); ?>

Download Download
$all_downloads_query->max_num_pages, 'current' => $current_page, 'format' => '?paged=%#%', 'show_all' => false, 'end_size' => 1, 'mid_size' => 2, 'prev_next' => true, 'prev_text' => '« Previous', 'next_text' => 'Next »', 'type' => 'array' ); $pagination_links = paginate_links($pagination_args); if ($pagination_links) { echo ''; } ?>
term_id]) && isset($category_queries[$category->term_id])): ?>
term_id]; $pagination_args = array( 'total' => $category_query->max_num_pages, 'current' => $current_page, 'format' => '?paged=%#%', 'show_all' => false, 'end_size' => 1, 'mid_size' => 2, 'prev_next' => true, 'prev_text' => '« Previous', 'next_text' => 'Next »', 'type' => 'array' ); $pagination_links = paginate_links($pagination_args); if ($pagination_links) { echo ''; } ?>