display posts from a category on the same page


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

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

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

$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() ) {

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.

pual 2 months 0 Answers 9 views 0

Leave an answer