display posts from a category on the same page

Question

I’m making a single page website where you can reach the articles and expand them.
So my hardcoded page looks like :

    <details>
      <summary>2019</summary>
        <p>first article of 2019</p>
        <p>second article from 2019</p>
    </details>
    <details>
      <summary>2018</summary>
        <p>first article of 2018</p>
        <p>second article from 2018</p>
    </details>

I’m looking for he best way to implement that into my wordpress theme, so I started doing that :

    <?php 
$categories = get_categories();
foreach($categories as $category) {
    echo '<div class="col-md-4"><a href="' . get_category_link($category->term_id) . '">' . $category->name . '</div>';

    if( have_posts() ){

        while( have_posts() ) {
            the_post();
            the_content();
        }
    }
}
?>

But I don’t know how to get the specific posts from each category to display inside that.
Could anyone help me?
thanks a lot.

0
pual 2 months 0 Answers 9 views 0

Leave an answer