改变Wordpress循环帖子显示

时间:2014-11-11 21:01:21

标签: php wordpress

我正在尝试使用Events Organizer插件更改将在事件存档页面上显示的帖子数量。现在,以下代码仅显示8个事件,因为这是Wordpress查询设置的内容。

如果我创建一个新查询并将其设置为post type =“event”,它将获取所有事件,而不仅仅是事件类别。

如何更改下面的代码,以确保它能够提取该事件​​类别中的所有帖子?

这是一个模板文件,因此所有事件类别都使用此模板。我试图找到一个简单的解决方案来改变帖子的数量,因为其他一切正确填充。

            <!-- Start Loop -->
                <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
                <div class="col-md-4 clearfix">
                <a href="<?php the_permalink(); ?>">
                    <?php if ( has_post_thumbnail() ) {
                        the_post_thumbnail('thumbnail');
                        }
                    ?>
                </a>
                <div class="event__details">
                <a href="<?php the_permalink(); ?>" class="event__title">
                        <?php the_title(); ?>

                </a>
                    <?php
                    if( eo_is_all_day() ){
                        $format = 'd F Y';
                        $microformat = 'Y-m-d';
                    }else{
                        $format = 'd F Y '.get_option('time_format');
                        $microformat = 'c';
                    }?>
                    <time itemprop="startDate" datetime="<?php eo_the_start($microformat); ?>">         <?php eo_the_start($format); ?></time>  
                </div>
                </div>
                <?php endwhile; ?>
                <?php endif; ?>
                <!-- End Loop -->

1 个答案:

答案 0 :(得分:0)

创建自定义WP_Query check this

<?php 

$args = array(
  'post_type' => 'event',
  'posts_per_page' => 8
);

$the_query = new WP_Query( $args ); ?>

<?php if ( $the_query->have_posts() ) : ?>

    <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
        <h2><?php the_title(); ?></h2>
    <?php endwhile; ?>

<?php wp_reset_postdata(); ?>

<?php else : ?>
    <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
相关问题