FEATURE introducing the file

This commit is contained in:
Antoine M 2025-06-10 15:01:47 +02:00
parent 0fe1c8b79f
commit a1a2583039

88
includes/api.php Normal file
View File

@ -0,0 +1,88 @@
<?php
add_action('rest_api_init', function () {
/* ----------------
BUILDING ROUTES
-----------------*/
// ################ NEWS ################
// * BUILD MORE NEWS CARDS
register_rest_route('dynamiques-datas/v1/build', '/revue/authors', array(
'methods' => 'GET',
'callback' => 'build_revue_authors',
'permission_callback' => '__return_true',
));
});
// ################ NEWS ################
function build_revue_authors($request)
{
write_log($request);
// $previousActivePage = esc_html($request->get_param('active-page')) ?? 1;
// $activeTermID = esc_html($request->get_param('active-term-id'));
// $postsPerPage = esc_html($request->get_param('posts-per-page')) ?? 12;
// $activePage = is_numeric($previousActivePage) ? $previousActivePage + 1 : 1;
// $taxQuery = $activeTermID && is_numeric($activeTermID) ? array(
// array(
// 'taxonomy' => 'news_type',
// 'field' => 'term_id',
// 'terms' => $activeTermID
// )
// ) : null;
// do_action('wpml_switch_language', $currentLanguage);
// $args = array(
// "status" => "publish",
// "post_type" => "post",
// "posts_per_page" => $postsPerPage,
// "paged" => $activePage,
// "tax_query" => $taxQuery
// );
// $newsPostsDatas = new WP_Query($args);
// ob_start();
// foreach ($newsPostsDatas->posts as $key => $post) {
// $post_thumbnail = get_the_post_thumbnail($post->ID, 'full', array('class' => 'card-news__thumbnail card-post__thumbnail')) ?? null;
// $news_type = get_the_terms($post->ID, "news_type") ?? null;
// $post_date = get_the_date('j.m.Y', $post->ID) ?? null;
// get_template_part(
// 'template-components/cards/card-news',
// null,
// array(
// 'card_variant' => 'activite',
// 'post_ID' => $post->ID,
// 'post_title' => get_the_title($post->ID),
// 'post_thumbnail' => $post_thumbnail,
// 'news_type' => $news_type,
// 'post_date' => $post_date,
// )
// );
// }
// $html_template = ob_get_clean();
// $response_data = array(
// 'html_template' => $html_template,
// 'total_posts_found' => $newsPostsDatas->found_posts,
// 'active_page' => $activePage,
// 'max_num_pages' => $newsPostsDatas->max_num_pages,
// );
$response = new WP_REST_Response($response_data);
$response->set_status(200);
return $response;
}