Amy-Mir / global-templates / home-posts.php
home-posts.php
Raw
<?php

// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;

$articles = array('first', 'second', 'third');

$categories   = get_categories();
$categories_query  = new WP_Query;

?>

<div class="blogCards__container">
    <?php
    
    foreach ( $categories as $category ) :
        
        $categories_query->query( array(
            'cat'                 => $category->term_id,
            'posts_per_page'      => 1,
            'no_found_rows'       => true,
            'ignore_sticky_posts' => true,
        ));
        
        while ( $categories_query->have_posts() ) : $categories_query->the_post();
        
        $postID = get_the_ID();
        $cat = get_the_category($postID)[0]; 

        $cover = get_field("cover", $postID);
        $introduction = get_field("introduction", $postID);

        $args = array(
            "image"              => $cover,
            "title"              => get_the_title(),   
            "intro"              => $introduction,    
            "postID"             => $postID,   
            "permalink"          => get_the_permalink(),
            "isArticle"          => false,
        );

        if($cat->name === "Article"):
            $args["isArticle"] = get_field("post_url", $postID);
        endif;
        
        get_template_part('loop-templates/cards', 'hblog', $args);

        endwhile;
    endforeach; 

    ?>
</div>