hadnling languages in api query and reorganising js file
This commit is contained in:
parent
43d82f4367
commit
0cead7296c
|
|
@ -37,7 +37,7 @@ add_action('rest_api_init', function () {
|
||||||
/* ----------------
|
/* ----------------
|
||||||
BUILDING ROUTES
|
BUILDING ROUTES
|
||||||
-----------------*/
|
-----------------*/
|
||||||
|
// * BUILD ALL NEWS CARDS
|
||||||
register_rest_route('homegrade-datas/v1/build', '/news', array(
|
register_rest_route('homegrade-datas/v1/build', '/news', array(
|
||||||
'methods' => 'GET',
|
'methods' => 'GET',
|
||||||
'callback' => 'build_news_posts_feed_all',
|
'callback' => 'build_news_posts_feed_all',
|
||||||
|
|
@ -56,27 +56,27 @@ add_action('rest_api_init', function () {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function build_card($request)
|
// function build_card($request)
|
||||||
{
|
// {
|
||||||
$cardId = $request['cardId'];
|
// $cardId = $request['cardId'];
|
||||||
|
|
||||||
|
|
||||||
$test = get_template_part(
|
// $test = get_template_part(
|
||||||
'template-components/cards/card-news',
|
// 'template-components/cards/card-news',
|
||||||
null,
|
// null,
|
||||||
array(
|
// array(
|
||||||
'card_variant' => 'activite',
|
// 'card_variant' => 'activite',
|
||||||
'post_ID' => $cardId,
|
// 'post_ID' => $cardId,
|
||||||
'post_title' => get_the_title($cardId),
|
// 'post_title' => get_the_title($cardId),
|
||||||
// 'post_thumbnail' => $post_thumbnail,
|
// // 'post_thumbnail' => $post_thumbnail,
|
||||||
// 'news_type' => $news_type,
|
// // 'news_type' => $news_type,
|
||||||
)
|
// )
|
||||||
);
|
// );
|
||||||
$response = new WP_REST_Response($test);
|
// $response = new WP_REST_Response($test);
|
||||||
$response->set_status(200);
|
// $response->set_status(200);
|
||||||
|
|
||||||
return $response;
|
// return $response;
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
function get_news($request)
|
function get_news($request)
|
||||||
|
|
@ -127,11 +127,11 @@ function build_news_posts_feed_all($request)
|
||||||
"post_type" => "post",
|
"post_type" => "post",
|
||||||
"posts_per_page" => -1,
|
"posts_per_page" => -1,
|
||||||
);
|
);
|
||||||
$newsPostsDatas = get_posts($args);
|
$newsPostsDatas = new WP_Query($args);
|
||||||
|
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
foreach ($newsPostsDatas as $key => $post) {
|
foreach ($newsPostsDatas->posts as $key => $post) {
|
||||||
$post_thumbnail = get_the_post_thumbnail($post->ID, 'full', array('class' => 'card-news__thumbnail card-post__thumbnail')) ?? null;
|
$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;
|
$news_type = get_the_terms($post->ID, "news_type") ?? null;
|
||||||
// write_log($news_type);
|
// write_log($news_type);
|
||||||
|
|
@ -163,6 +163,7 @@ function build_news_posts_feed_per_type_id($request)
|
||||||
$args = array(
|
$args = array(
|
||||||
"post_type" => "post",
|
"post_type" => "post",
|
||||||
"posts_per_page" => -1,
|
"posts_per_page" => -1,
|
||||||
|
|
||||||
"tax_query" => array(
|
"tax_query" => array(
|
||||||
array(
|
array(
|
||||||
'taxonomy' => 'news_type',
|
'taxonomy' => 'news_type',
|
||||||
|
|
@ -171,11 +172,11 @@ function build_news_posts_feed_per_type_id($request)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$newsPostsDatas = get_posts($args);
|
$newsPostsDatas = new WP_Query($args);
|
||||||
|
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
foreach ($newsPostsDatas as $key => $post) {
|
foreach ($newsPostsDatas->posts as $key => $post) {
|
||||||
$post_thumbnail = get_the_post_thumbnail($post->ID, 'full', array('class' => 'card-news__thumbnail card-post__thumbnail')) ?? null;
|
$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;
|
$news_type = get_the_terms($post->ID, "news_type") ?? null;
|
||||||
get_template_part(
|
get_template_part(
|
||||||
|
|
|
||||||
|
|
@ -1,25 +1,16 @@
|
||||||
function loadMoreNewsInit() {
|
async function filterPosts(e) {
|
||||||
const loadMoreButton = document.querySelector('#load-more-news');
|
const filterID =
|
||||||
if (!loadMoreButton) return;
|
e.target.getAttribute('data-term-id') ??
|
||||||
|
e.target.parentElement.getAttribute('data-term-id') ??
|
||||||
|
null;
|
||||||
|
|
||||||
function loadMoreNews() {
|
const filterButtons = document.querySelectorAll('.filters-toolbar__action-button');
|
||||||
console.log('loadMoreNews');
|
|
||||||
}
|
|
||||||
|
|
||||||
loadMoreButton.addEventListener('click', loadMoreNews);
|
|
||||||
}
|
|
||||||
|
|
||||||
function filterNewsInit() {
|
|
||||||
const filterNewsToolbar = document.querySelector('.filters-toolbar--archive-news');
|
|
||||||
if (!filterNewsToolbar) return;
|
|
||||||
|
|
||||||
const filterButtons = filterNewsToolbar.querySelectorAll('.filters-toolbar__action-button');
|
|
||||||
if (!filterButtons) return;
|
|
||||||
|
|
||||||
filterButtons.forEach((button) => {
|
filterButtons.forEach((button) => {
|
||||||
const termId = button.getAttribute('data-term-id');
|
button.classList.remove('filters-toolbar__action-button--active');
|
||||||
button.addEventListener('click', (e) => filterPosts(e));
|
|
||||||
});
|
});
|
||||||
|
await hydrateNewsFeedByTypeId(filterID);
|
||||||
|
e.target.classList.add('filters-toolbar__action-button--active');
|
||||||
}
|
}
|
||||||
|
|
||||||
async function hydrateNewsFeedByTypeId(filterID) {
|
async function hydrateNewsFeedByTypeId(filterID) {
|
||||||
|
|
@ -36,25 +27,30 @@ async function hydrateNewsFeedByTypeId(filterID) {
|
||||||
container.innerHTML = newCardsContent;
|
container.innerHTML = newCardsContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function filterPosts(e) {
|
function filterNewsInit() {
|
||||||
const filterID =
|
const filterNewsToolbar = document.querySelector('.filters-toolbar--archive-news');
|
||||||
e.target.getAttribute('data-term-id') ??
|
if (!filterNewsToolbar) return;
|
||||||
e.target.parentElement.getAttribute('data-term-id') ??
|
|
||||||
null;
|
const filterButtons = filterNewsToolbar.querySelectorAll('.filters-toolbar__action-button');
|
||||||
console.log('filterID');
|
if (!filterButtons) return;
|
||||||
console.log(filterID);
|
|
||||||
const filterButtons = document.querySelectorAll('.filters-toolbar__action-button');
|
|
||||||
|
|
||||||
filterButtons.forEach((button) => {
|
filterButtons.forEach((button) => {
|
||||||
button.classList.remove('filters-toolbar__action-button--active');
|
const termId = button.getAttribute('data-term-id');
|
||||||
|
button.addEventListener('click', (e) => filterPosts(e));
|
||||||
});
|
});
|
||||||
await hydrateNewsFeedByTypeId(filterID);
|
}
|
||||||
e.target.classList.add('filters-toolbar__action-button--active');
|
function loadMoreNewsInit() {
|
||||||
|
const loadMoreButton = document.querySelector('#load-more-news');
|
||||||
|
if (!loadMoreButton) return;
|
||||||
|
|
||||||
|
function loadMoreNews() {
|
||||||
|
console.log('loadMoreNews');
|
||||||
|
}
|
||||||
|
|
||||||
|
loadMoreButton.addEventListener('click', loadMoreNews);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function archiveNewsInit() {
|
export default function archiveNewsInit() {
|
||||||
loadMoreNewsInit();
|
|
||||||
filterNewsInit();
|
filterNewsInit();
|
||||||
|
loadMoreNewsInit();
|
||||||
const cardNewsElements = document.querySelectorAll('.card-news');
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user