如何使用wordpress代码将自定义文章类型显示为网格视图


How to display custom post type as a gridview using wordpress code

我有一个自定义的post类型"events",我想在一个由3列组成的表中显示事件,并使用wordpress中的代码进行分页。

这是我到目前为止所做的,但它显示为一个列表。

$loop = new WP_Query( array( 'post_type' => 'events' , 'posts_per_page' => 3) );
    $count = $loop->post_count;
    if ( $loop->have_posts() ) :
    ?>
    <h2 style="position:relative;top:100px" align="center"> News & Events</h2>
    <div id = "menu" style="position:relative;top:100px;left:350px">
    <ul>
      <li class = "aa"><a class="anchor" id="all"  href="#">All</a></li>
      <li  class = "aa"><a  class="anchor" id ="videos" href="#">Videos</a></li>
      <li  class = "aa"><a  class="anchor" name = "links" id="links" href="#">Links</a></li>
      <li  class = "aa"><a  class="anchor" id = "our events" name ="our events" href="#">Our Events</a></li>
    </ul>
    </div>
    <br>
    <br><br>
    <?php
        while ( $loop->have_posts() ) : $loop->the_post(); ?>

            <div class="pindex" style="position:relative;top:100px;left:-450px">
                <?php if ( has_post_thumbnail() ) { ?>
                    <div class="pimage">
                        <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(); ?></a>
                    </div>
                <?php } ?>
                <div class="ptitle">
                    <h2><?php 
                    echo get_the_title() ?></h2>
                <div style="width:20%;position:relative;top:10px;left:550px" ><?php echo the_content();?>   </div>
                </div>
            </div>
        <?php 
        endwhile;
        if (  $loop->max_num_pages > 1 ) : ?>
            <div id="nav-below" class="navigation">
                <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Previous', 'domain' ) ); ?></div>
                <div class="nav-next"><?php previous_posts_link( __( 'Next <span class="meta-nav">&rarr;</span>', 'domain' ) ); ?></div>
            </div>
        <?php endif;
    endif;
    wp_reset_postdata();

有人能帮我吗?

您使用此方法来显示自定义的post events和分页,因为它是

$args = array( 
   'post_type' => 'events', 
   'posts_per_page' => 3
);
$posts_array = get_posts( $args );
// print_r($posts_array);
foreach ( $posts_array as $post ){
   echo $post->ID;
}