$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>Display Custom Post Type in divs|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

Display Custom Post Type in divs

matteradmin10PV0评论

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>
Post a comment

comment list (0)

  1. No comments so far