homegrade_blocks_production/blocks/communiques-presse-feed/src/edit.js

99 lines
2.4 KiB
JavaScript

import { __ } from "@wordpress/i18n";
import { useBlockProps } from "@wordpress/block-editor";
import { useSelect } from "@wordpress/data";
import "./editor.scss";
import { useEntityRecords } from "@wordpress/core-data";
import { InnerBlocks } from "@wordpress/block-editor";
export default function Edit() {
const lang = "fr";
// const items = useEntityRecords("postType", "post", {
// per_page: -1,
// status: "publish",
// // taxonomy: "news_type",
// news_type: [1],
// });
const newsPosts = useSelect((select) =>
select("core").getEntityRecords("postType", "post", {
per_page: -1,
status: "publish",
news_type: [95],
})
);
if (newsPosts) {
console.log(newsPosts);
}
return (
<section
{...useBlockProps({
className: `homegrade-blocks-communiques-presse-feed`,
})}
>
<InnerBlocks
allowedBlocks={[
"homegrade-content-blocks/section-titling",
"core/paragraph",
]}
template={[
[
"homegrade-content-blocks/section-titling",
{
sectionTitle: __(
"Communiqués de presse",
"homegrade-blocks__texte-fonctionnel"
),
},
],
]}
templateLock={true}
/>
<p className="temp_guidance_sentence">
{__(
"Les éléments déposés dans le press photo kit press s'afficheront ici",
"homegrade-blocks__text-backoffice"
)}
</p>
<p style={{ textAlign: "center" }}>
Les communiqués de presses seront affichés ici
</p>
<div class="card-grid-container">
{newsPosts &&
newsPosts.map((post) => {
return (
<>
<div className="card-news">
{/* <?php echo $post_thumbnail ?> */}
<div class="card-news__inner">
<div class="card-news__heading">
<h3 class="card-news__title">{post.title.rendered}</h3>
</div>
<a
href="#"
class="cta cta--read-more cta--with-arrow-button cta--streched "
>
<span>
{__(
"Lire l'article",
"homegrade-theme__texte-fonctionnel"
)}
</span>
<span class="sr-only">{post.title.rendered}</span>
<img
class="cta_arrow_button"
src="<?php echo get_template_directory_uri() ?>/resources/img/graphic-assets/arrow-right-circle.svg"
alt=""
/>
</a>
</div>
</div>
</>
);
})}
</div>
</section>
);
}