简体   繁体   English

更改Wordpress循环帖子显示

[英]Alter Wordpress Loop Posts Display

I am trying to alter the number of posts that will display on an events archive page using the Events Organiser plugin. 我正在尝试使用事件管理器插件更改将显示在事件存档页面上的帖子数。 Right now the following code displays only 8 events because that is what the Wordpress query is set to. 现在,以下代码仅显示8个事件,因为那是Wordpress查询设置的。

If I create a new query and set it to post type="event" it will grab all events and not just from the event category. 如果我创建一个新查询并将其设置为post type =“ event”,它将捕获所有事件,而不仅仅是事件类别。

How can I alter the code below to be able to make sure it pulls all posts in that event category? 如何更改下面的代码,以确保能够提取该事件​​类别中的所有帖子?

This is a template file so all event categories use this template. 这是一个模板文件,因此所有事件类别都使用此模板。 I am trying to find an easy solution to alter the number of posts since everything else is populating correctly. 我试图找到一种简单的解决方案来更改帖子的数量,因为其他所有内容都正确填充。

            <!-- 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 -->

create a custom WP_Query check this 创建一个自定义WP_Query 检查此

<?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; ?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM