From fb4bdc673dc28e1d6f3d2961e72c130ff40a6c2e Mon Sep 17 00:00:00 2001 From: Antoine M Date: Thu, 26 Oct 2023 17:51:48 +0200 Subject: [PATCH] updating news pages system --- resources/css/pages/single-news.css | 13 +++ resources/js/archive-template-news.js | 23 +++- single-post.php | 63 +++++++++++ template-news.php | 149 ++++++++++++++++---------- 4 files changed, 186 insertions(+), 62 deletions(-) create mode 100644 resources/css/pages/single-news.css create mode 100644 single-post.php diff --git a/resources/css/pages/single-news.css b/resources/css/pages/single-news.css new file mode 100644 index 0000000..cb36c8c --- /dev/null +++ b/resources/css/pages/single-news.css @@ -0,0 +1,13 @@ +body.acoustisque { + @apply bg-slate-800; +} +.entry-content.single-news-editor-content { + @apply mx-auto mt-8 px-4; + ul li::marker, + ol li::marker { + @apply text-purple-500; + } + ul li:before { + @apply !bg-secondary; + } +} diff --git a/resources/js/archive-template-news.js b/resources/js/archive-template-news.js index 895e570..97c6d8a 100644 --- a/resources/js/archive-template-news.js +++ b/resources/js/archive-template-news.js @@ -13,17 +13,16 @@ function filterNewsInit() { const filterNewsToolbar = document.querySelector('.filters-toolbar--archive-news'); if (!filterNewsToolbar) return; - const filterButtons = filterNewsToolbar.querySelectorAll('.filter__action-button'); + const filterButtons = filterNewsToolbar.querySelectorAll('.filters-toolbar__action-button'); if (!filterButtons) return; filterButtons.forEach((button) => { const termId = button.getAttribute('data-term-id'); - button.addEventListener('click', hydrateNewsFeedByTypeId); + button.addEventListener('click', (e) => filterPosts(e)); }); } -async function hydrateNewsFeedByTypeId(e) { - const filterID = e.target.getAttribute('data-term-id'); +async function hydrateNewsFeedByTypeId(filterID) { let newCardsContent; if (filterID === 'all') { const response = await fetch(`/wp-json/homegrade-datas/v1/build/news`); @@ -37,6 +36,22 @@ async function hydrateNewsFeedByTypeId(e) { container.innerHTML = newCardsContent; } +async function filterPosts(e) { + const filterID = + e.target.getAttribute('data-term-id') ?? + e.target.parentElement.getAttribute('data-term-id') ?? + null; + console.log('filterID'); + console.log(filterID); + const filterButtons = document.querySelectorAll('.filters-toolbar__action-button'); + + filterButtons.forEach((button) => { + button.classList.remove('filters-toolbar__action-button--active'); + }); + await hydrateNewsFeedByTypeId(filterID); + e.target.classList.add('filters-toolbar__action-button--active'); +} + export default function archiveNewsInit() { loadMoreNewsInit(); filterNewsInit(); diff --git a/single-post.php b/single-post.php new file mode 100644 index 0000000..f921945 --- /dev/null +++ b/single-post.php @@ -0,0 +1,63 @@ + '_wp_page_template', + 'meta_value' => "template-news.php" +); +$relatedPageTemplatePage = get_pages($args) ? get_pages($args)[0] : null; +?> + + + + + + + +
+ + get_the_terms(get_the_ID(), 'news-type'), + "title" => get_the_title(), + "thumbnail" => get_the_post_thumbnail(get_the_ID(), "full", array('class' => 'news-heading-box__thumbnail')), + "published" => get_the_date() + + )); + ?> +
+ +
+
+ + + + + + + + + +
+ -
-
- -

-

-
- - - "post", - "status" => "publish", - "posts_per_page" => $post_per_page, - -); -$posts = new WP_Query($args); - - -?> -
- -
+ +
    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; + $news_types = get_terms(array( + 'taxonomy' => 'news-type', + 'hide_empty' => true, + )); - get_template_part( - 'template-components/cards/card-news', - null, - array( - 'card_variant' => 'activite', - 'post_ID' => $post->ID, - 'post_title' => $post->post_title, - 'post_thumbnail' => $post_thumbnail, - 'news_type' => $news_type, - ) - ); - } ?> -
+
  • + +
  • + + term_id) ?? null; + + ?> +
  • + +
  • + + + + + + +
    + "post", + "status" => "publish", + "posts_per_page" => $post_per_page, + + ); + $posts = new WP_Query($args); + ?> + +
    + + 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; + + get_template_part( + 'template-components/cards/card-news', + null, + array( + 'card_variant' => 'activite', + 'post_ID' => $post->ID, + 'post_title' => $post->post_title, + 'post_thumbnail' => $post_thumbnail, + 'news_type' => $news_type, + ) + ); + } + ?> +
    + + + max_num_pages > 1) : ?> + + +
    + + - max_num_pages > 1) : ?> - - -