Frage

Would appreciate help. I'm trying to figure out how to build a menu page where there are pictures or photos with a summary with a link to a post or article. Like a grid or a similar shape. (Not using categories) It's clear to me that this is probably a basic thing that I have not been able to crack gently :( Thanks in advance.

War es hilfreich?

Lösung

Use WP_Query for getting the posts you want. Then you can loop through them and get their title, their featured image and their excerpt to be printed they way you want. Something like that:

<?php $args = [
    'post_type'      => 'post',
    'post_status'    => 'publish',
    'posts_per_page' => 9,
    'order'          => 'DESC',
    'orderby'        => 'date',
]; ?>

<?php $the_query = new WP_Query( $args ); ?>

<?php if ( $the_query->have_posts() ) : ?>
    <div class="my-grid">

    <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
        <div class="grid-item">

           <div class="thumbnail"><?php the_post_thumbnail(); ?></div>
           <div class="title"><?php the_title(); ?></div>
           <div class="excerpt"><?php the_excerpt(); ?></div>

        </div>
    <?php endwhile; ?>

    <?php wp_reset_postdata(); ?>

    </div>
<?php else : ?>
    <p><?php esc_html_e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>

And the rest is just CSS.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit wordpress.stackexchange
scroll top