如何在列中显示自定义文章类型的循环

时间:2018-05-07 作者:Esteban Martinez

希望一切顺利。我编写了一个小部件,它显示来自自定义帖子类型“Staff”的帖子。每当客户添加新员工时,都会显示他们的姓名和特征图像。我的问题是:如何让这些“帖子”填充列?理想情况下,我希望有2行4列。以下是我的小部件代码:

public function widget($args, $instance) {

    //Arguments that you can pass through the widget function. We are displaying only the CPT \'News\' in our widget

    $args = array(
        \'post_type\' => \'Staff\',
        \'posts_per_page\' => -1,
    );

    //Loop through Custom Post Type in there are posts and if we are currently on a single Program page. (\'program\' must be lowercase) EDIT is_singular is now empty to show on all singular pages in general

    $loop = new WP_Query($args);

    if($loop->have_posts() && is_singular(\'\')):
        while($loop->have_posts()) {

            $loop->the_post();

            //What will be displayed physically in the widget for each item

            echo \'<br />\';
            the_title();
            echo \'<div class="entry-content">\';
            the_post_thumbnail(\'thumbnail\');
            the_content();
            echo \'</div>\';


        }endif;


    wp_reset_postdata();
}
任何帮助都将不胜感激!

1 个回复
SO网友:BlueSix

这是一个HTML/CSS问题。您的PHP基本上都很好。您只需删除<br> 从您的代码。

然后,在CSS中,使用“float”将div变成列。更多信息https://learn.co/lessons/css-column-structure-using-floats

结束

相关推荐

Loop increase number

$args = array( \'post_type\' => \'events\', \'order\' => \'ASC\', ); $wp_query = new WP_Query($args); ?> <script type=\"application/ld+json\"> { \"@context\":\"http://schema.org\", \"