簡體   English   中英

更改Wordpress循環帖子顯示

[英]Alter Wordpress Loop Posts Display

我正在嘗試使用事件管理器插件更改將顯示在事件存檔頁面上的帖子數。 現在,以下代碼僅顯示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 -->

創建一個自定義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