Display Custom Post Type in divs

admin2025-06-06  1

I'm sorry if this is a already asked Question but i'm trying to get my custom post types displayed in grid like this:

<div class="row>
     <div class="col-md-4>
         /* Start the Loop */
         while (have_posts()) : the_post();
         get_template_part('template-parts/post/content', get_post_format());
         endwhile; // End of the loop.
     </div>
</div

that mean i would like to Display every post in a div with the class col-md-4

I'm sorry if this is a already asked Question but i'm trying to get my custom post types displayed in grid like this:

<div class="row>
     <div class="col-md-4>
         /* Start the Loop */
         while (have_posts()) : the_post();
         get_template_part('template-parts/post/content', get_post_format());
         endwhile; // End of the loop.
     </div>
</div

that mean i would like to Display every post in a div with the class col-md-4

Share Improve this question edited Oct 31, 2018 at 20:06 MisterLA asked Oct 31, 2018 at 19:47 MisterLAMisterLA 52 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 0

You'll want to move the row/columns inside the loop to do this. Perhaps even inside the template part. Seeing as I don't know what's in there, I'd suggest this: (notice I corrected your missing " at the end of div classes and added php start/stop)

<div class="row">
<?php
     /* Start the Loop */
     while (have_posts()) : the_post();
       echo '<div class="col-md-4">';
       get_template_part('template-parts/post/content', get_post_format());
       echo '</div>';
     endwhile; // End of the loop.
?>
</div>

this is fine if there are only 4 items in your row. or your system handles row calculations for you. If it doesn't you'll need to move the row call into the loop as well and add item count and then if statements for the 1st and every 4th item after that.

The Thing is that i was trying to Display only the thumb and the title of the post inside the thumb with a "got to this Portfolio" button.

Something like this:

        <div class="portfolio">
            <div class="row">
            <?php
                $args = array( 'post_type' => 'portfolio', 'posts_per_page' => 10 );
                $loop = new WP_Query( $args );
                while ( $loop->have_posts() ) : $loop->the_post();
                    echo '<div class="col-md-4">';
                    the_title();
                    //here the thumb
                    //Here the "Go to Portfolio" Button
                    echo '</div>';
                endwhile;
            ?>
            </div>
        </div>
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749214164a317319.html

最新回复(0)