<?php $args = array( 'post_type' => 'news', // Change 'news' to your custom"/>
星期三 , 22 1 月 2025

首篇文章和别的文章不一样如何一起输出

<div class="list">
    <?php
    $args = array(
        'post_type' => 'news', // Change 'news' to your custom post type name
        'posts_per_page' => 4, // Number of posts to display
    );

    $query = new WP_Query($args);

    if ($query->have_posts()) {
        $first_post = true; // Flag to check the first post

        while ($query->have_posts()) {
            $query->the_post();
            ?>
            <a href="<?php the_permalink(); ?>">
                <div class="slide">
                    <?php if ($first_post) : ?>
                        <div class="time">
                            <b><?php echo get_field('time'); ?></b> <?php echo get_the_date('Y-m'); ?>
                        </div>
                        <div class="txtbox">
                            <div class="c1"><?php the_title(); ?></div>
                            <div class="c2"><?php echo get_field('c2'); ?></div>
                        </div>
                    <?php else : ?>
                        <div class="c3">-&emsp;<?php the_title(); ?></div>
                        <div class="c4"><?php echo get_the_date('Y-m'); ?></div>
                    <?php endif; ?>
                </div>
            </a>
            <?php
            $first_post = false; // Set the flag to false after the first post
        }

        wp_reset_postdata();
    } else {
        echo 'No posts found';
    }
    ?>
</div>