简体   繁体   中英

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.

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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