I've started working on a wordpress theme for Full-site-editing but now I need to get the ID of each post shown on the archive page.
My archive.html looks like this:
<!-- wp:template-part {"slug":"topbar","tagName":"topbar","className":"site-topbar"} /-->
<!-- wp:template-part {"slug":"header","tagName":"header","className":"site-header"} /-->
<!-- wp:group {"align":"full","className":"site-inner"} -->
<div class="wp-block-group alignfull site-inner">
<!-- wp:group {"className":"content-sidebar-wrap"} -->
<div class="wp-block-group content-sidebar-wrap">
<!-- wp:group {"tagName":"main","align":"wide","className":"site-content"} -->
<main class="wp-block-group alignwide site-content">
<!-- wp:group {"align":"wide","layout":{"inherit":true}} -->
<div class="wp-block-group alignwide">
<!-- wp:group {"align":"wide"} -->
<div class="wp-block-group alignwide">
<!-- wp:pattern {"slug":"theamy/archive-title"} /-->
<!-- wp:term-description /-->
</div>
<!-- /wp:group -->
</div>
<!-- /wp:group -->
<!-- wp:pattern {"slug":"theamy/query-archive-grid"} /-->
</main>
<!-- /wp:group -->
</div>
<!-- /wp:group -->
</div>
<!-- /wp:group -->
<!-- wp:template-part {"slug":"footer","tagName":"footer","className":"site-footer"} /-->
and my archive query looks like this:
<?php
/**
* Title: Grid of posts in one column.
* Slug: theamy/query-archive-grid
* Categories: theamy-query
*/
?>
<!-- wp:group {"tagName":"section","align":"full","layout":{"inherit":true}} -->
<section class="is-layout-constrained wp-block-group alignfull theamy-query-archive-grid">
<?php do_action('query-archive-grid-start'); ?>
<!-- wp:query {"queryId":0,"query":{"perPage":12,"pages":0,"offset":0,"postType":"post","order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"","inherit":true,"taxQuery":null},"displayLayout":{"type":"grid"},"align":"wide","layout":{"inherit":false},"lock":{"move":false,"remove":false}} -->
<div class="wp-block-query alignwide">
<!-- wp:post-template {"align":"wide"} -->
<!-- wp:group {"tagName":"article","layout":{"inherit":false}} -->
<article class="wp-block-group">
<!-- wp:post-featured-image {"isLink":true} /-->
<!-- wp:group {"tagName":"header","className":"entry-header","layout":{"inherit":false}} -->
<header class="wp-block-group entry-header">
<!-- wp:group {"className":"entry-meta","layout":{"type":"block"}} -->
<div class="wp-block-group entry-meta">
<!-- wp:post-date {"format":"j F Y"} /-->
</div>
<!-- /wp:group -->
<!-- wp:post-title {"isLink":true} /-->
</header>
<!-- /wp:group -->
<!-- wp:group {"className":"entry-content","layout":{"inherit":false}} -->
<div class="wp-block-group entry-content">
<!-- wp:post-excerpt {"moreText":"Lees verder","showMoreOnNewLine":true} /-->
</div>
<!-- /wp:group -->
<!-- wp:group {"tagName":"footer","className":"entry-footer","layout":{"inherit":false}} -->
<footer class="wp-block-group entry-footer"></footer>
<!-- /wp:group -->
</article>
<!-- /wp:group -->
<!-- /wp:post-template -->
<!-- wp:query-pagination {"align":"wide","layout":{"type":"flex","justifyContent":"center"}} -->
<!-- wp:query-pagination-previous {"label":"<"} /-->
<!-- wp:query-pagination-numbers /-->
<!-- wp:query-pagination-next {"label":">"} /-->
<!-- /wp:query-pagination -->
<!-- wp:query-no-results -->
<!-- wp:paragraph -->
<p><?php echo __('Geen resultaten gevonden.', 'theamy') ?></p>
<!-- /wp:paragraph -->
<!-- /wp:query-no-results -->
</div>
<!-- /wp:query -->
</section>
<!-- /wp:group -->
I've tried to use get_the_ID() and get_queried_object_id(); but this did not seem to work.
I hope there's an easy fix for this but I could sadly not find it.
Each post is put in a <li>
with a class called "post-{id}", so I could use javascript to retrieve the post id but I'm not sure if that will do the trick for me and I rather not use javascript if it is not necessary.
thank you in advance for the help.
Kind regards, Janwillem