0

I'm getting stucked with the layout of the_post function.

I would love to have two post thumbnails per row and above the thumbnails the description, title, category of the post.

If I use flex property it shows to me all of those above in row.

any help?

php

body

website

Here is the code updated: HTML / PHP

<?php
        // the query
        $the_query = new WP_Query(array(
            'category_name' => 'first_4',
            'post_status' => 'publish',
            'posts_per_page' => 4,
        ));
?>

<div class='article-container'>
            <?php if ($the_query->have_posts()) : ?>
                <?php while ($the_query->have_posts()) : $the_query->the_post(); ?> 
    <div class='article-row'>
        <div class='article-column'>
                        <?php the_post_thumbnail(); ?>  
        </div>
                       <div class='article-info'>
                           <span><?php the_category(); ?></span> 
                           <span> <?php the_title(); ?></span> 
                           <span> <?php the_excerpt(); ?></span> 
                           <span> <?php the_content(); ?></span> 
                        </div> 
    </div>
                    <?php endwhile; ?>
                    <?php wp_reset_postdata(); ?>

                <?php else : ?> 
                    <p><?php __('No News'); ?></p>
                <?php endif; ?>
</div>

<?php

and HERE the CSS

.article-container {
display: flex; 
flex-flow: row wrap;
justify-content: space-between;
margin: auto;
}

.article-container .article-row {
    box-sizing: border-box;
    width: 48%;
}

.article-row .article-column img{
    width: 100%; 
    height: auto;

It seems to work but any advice will be appreciated! Of course I'm just learning as a passion =)

5
  • the_post() doesn't output any layout. It just sets up data so that functions like the_title() display the correct title, and those functions just output raw text. If you want to lay them out in a particular way you need to wrap them in your own HTML so that you can style them the way you want with basic HTML and CSS techniques. You should look at the default themes to see how they work. Commented Jan 25, 2022 at 10:09
  • Yes Jacob sorry, the_post does not output anything you are totally right. I just don't understand how to wrap the_category, the_title, etc to let the images display in a row but the rest below the images. =) I will try to look at a default themes.
    – Jettolo
    Commented Jan 25, 2022 at 10:21
  • You just need to wrap things in appropriate HTML tags and use CSS to style them. The same way you would on a plain HTML page. There’s no special WordPress approach. Commented Jan 25, 2022 at 10:36
  • For future reference, paste code here rather than screen grabs. If I wanted to attempt to and replicate what you're doing, and see if I could assist, I'd have to type everything out, which drastically reduces the likelihood that someone will. I think what you're asking for isn't all that hard to fix. The different tags you're using to bring in content are out of order. But even failing that, if you did flex-direction: column-reverse; and then justify-content: flex-start; you'd already start to see what you're after. Commented Jan 25, 2022 at 23:48
  • Dear @TonyDjukic yes, thanks for the advice. I changed a bit the tags and know it is much better. In the future, I will paste the code!
    – Jettolo
    Commented Jan 26, 2022 at 14:29

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.