refining links handling in menu renovateur to accept both taxonomy term or conseil page as input

This commit is contained in:
Antoine M 2023-10-10 14:53:01 +02:00
parent 4a8d8c7f7e
commit 5c1748482d
5 changed files with 77 additions and 23 deletions

2
.gitignore vendored
View File

@ -7,4 +7,4 @@ Makefile
init_script.sh
/css
/js
./css
.env

View File

@ -65,6 +65,10 @@ function getMainThematique($thematique)
}
// Get automatic post used in BLOCK QUESTIONS FREQUENTES
function get_automatic_post($post_type)
{

View File

@ -7,6 +7,7 @@
.chapter_index {
@apply bg-gray
w-full
lg:max-w-lg
p-12
h-fit

View File

@ -30,7 +30,6 @@ function build_chapter_index($blocks)
}
?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<?php
@ -78,8 +77,8 @@ function build_chapter_index($blocks)
?>
<?php get_template_part('template-components/post-conseils/chapter-header'); ?>
<div class=" conseils_wrapper">
<?php if ($chapterBlockIndex) : ?>
<aside class="chapter_index">
<aside class="chapter_index">
<?php if ($chapterBlockIndex) : ?>
<div class="chapter_index__titling">
<div class="icon"></div>
<h2 class="chapter_index__title">Dans ce conseil</h2>
@ -90,8 +89,8 @@ function build_chapter_index($blocks)
<li class="chapter_index__link"><a href="<?php echo $chapter['anchor'] ?>"><?php echo $chapter['title'] ?></a></li>
<?php endforeach; ?>
</ul>
</aside>
<?php endif; ?>
<?php endif; ?>
</aside>
<!-- CHAPTER INDEX -->

View File

@ -8,6 +8,8 @@ $logoSRC = wp_get_attachment_image_src($logoID, 'full');
?>
<div class="menu-renovateur">
<div class="website_logo">
@ -34,10 +36,10 @@ $logoSRC = wp_get_attachment_image_src($logoID, 'full');
foreach ($menuitems as $key => $item) :
// write_log("item");
// write_log($item);
$link = $item->url;
$title = $item->title;
// write_log("item");
// write_log($item);
// $pageIcon = get_field('page_icon', $item->ID);
// echo '<pre>';
@ -112,23 +114,71 @@ $logoSRC = wp_get_attachment_image_src($logoID, 'full');
<li class="submenu-item sub-menu__navlist__item">
<?php
// #### IF IS TAXONOMY SUB-ITEM
if ($item->type === "taxonomy") :
$term = get_term_by('id', $item->object_id, 'thematiques');
$cover = get_field('taxonomy_pictures', "thematiques_" . $item->object_id);
<?php // #### WHEN IS POST TYPE CONSEIL SUB ITEM
?>
<a href="<?php echo get_term_link($term) ?>">
<img class="sub-menu__navlist__thematique-icon" src="<?php echo $cover['icon']['url'] ?>" alt="">
<div class="details">
<h6><?php echo $title; ?></h6>
<p class="sub-menu__navlist__description"><?php echo $term->description ?></p>
</div>
</a>
<?php else : ?>
<?php if ($item->type === "post_type" && $item->type_label === "Conseil") : ?>
<?php
$postThematique = get_the_terms($item->object_id, "thematiques")[0];
$postParentThematique = getParentThematique($postThematique);
$thematiqueCover = get_field('taxonomy_pictures', "thematiques_" . $postParentThematique->term_id);
?>
<?php if ($postThematique) : ?>
<a href="<?php echo $item->url ?>">
<img class="sub-menu__navlist__thematique-icon" src="<?php echo $thematiqueCover['icon']['url'] ?>" alt="">
<div class="details">
<h6><?php echo $postThematique->name ?></h6>
<p class="sub-menu__navlist__description"><?php echo $postParentThematique->description ?></p>
</div>
</a>
<?php endif; ?>
<?php // WHEN THE SUB-LINK IS A TAXONOMY TERM
?>
<?php elseif ($item->type === "taxonomy") : ?>
<?php
$term = get_term($item->object_id, 'thematiques');
$mainTaxonomyParent = getMainThematique($term);
$args = array(
'post_type' => 'conseils',
'posts_per_page' => 1,
'tax_query' => array(
array(
'taxonomy' => 'thematiques',
'field' => 'slug',
'terms' => $mainTaxonomyParent->slug,
'include_children' => false,
),
),
);
$taxonomyRelatedPost = get_posts($args)[0] ?? null;
$cover = get_field('taxonomy_pictures', "thematiques_" . $mainTaxonomyParent->term_id);
?>
<?php if ($taxonomyRelatedPost) : ?>
<a href="<?php echo get_permalink($taxonomyRelatedPost->ID) ?>">
<img class="sub-menu__navlist__thematique-icon" src="<?php echo $cover['icon']['url'] ?>" alt="">
<div class="details">
<h6><?php echo $title; ?></h6>
<p class="sub-menu__navlist__description"><?php echo $mainTaxonomyParent->description ?></p>
</div>
</a>
<?php else : ?>
<a href="<?php echo get_permalink($taxonomyRelatedPost->ID) ?>">
<img class="sub-menu__navlist__thematique-icon" src="<?php echo $cover['icon']['url'] ?>" alt="">
<div class="details">
<h6><?php echo $title; ?></h6>
<p class="sub-menu__navlist__description"><?php echo $mainTaxonomyParent->description ?></p>
<p class="!text-red-500 text-xs uppercase">pas de page conseil liée à cette thématique</p>
</div>
</a>
<?php endif; ?>
<?php else : ?>
<p>`qsdqsd</p>
<a href="<?php echo $link; ?>" class="title"><?php echo $title; ?></a>
<?php endif; ?>
</li>