0

以下内容开箱即用,页面需要永远加载,它会创建大量 Apache 进程并疯狂消耗内存和 CPU

<?php

/**
 * Template Name: Custom forum index
 */

get_header();


?>
            <div id="content" role="main">

                <?php //do_action( 'bbp_template_notices' ); ?>

                <?php
                $args = array(
                   'post_type' => 'forum',
                   'post_status' => 'publish',
                   //'meta_key' => 'age',
                   'orderby' => 'title',
                   'order' => 'ASC',
                   // 'meta_query' => array(
                        // array(
                           // 'key' => '_bbp_topic_count'
                        // ),
                        // array(
                            // 'key' => '_bbp_reply_count'
                        // ),
                        // array(
                            // 'key' => '_bbp_last_active_time'
                        // ),
                        // array(
                            // 'key' => '_bbp_last_topic_id'
                        // )
                    // )
                );
                $query = new WP_Query($args);

                while ($query->have_posts()) : the_post(); ?>

                    <div id="forum-front" class="bbp-forum-front">
                        <h1 class="entry-title"><?php the_title(); ?></h1>
                        <div class="entry-content">

                            <?php //the_content(); ?>

                            <?php //bbp_get_template_part( 'content', 'archive-forum' ); ?>

                        </div>
                    </div><!-- #forum-front -->

                <?php endwhile; ?>

            </div><!-- #content -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>  

潜在的动机是我正在尝试创建一个自定义论坛索引页面,论坛根据其名称按字母顺序排列。奇怪的是,bbPress 并没有这样的功能

正如您在上面看到的,我尝试使用 WP_Query() 来循环访问类型为“forum”的帖子。这种方法可能出了什么问题?我需要在这里对 WP_Query() 做什么?

4

2 回答 2

0

由于使用 custom WP_Query,您需要在关键字wp_reset_query();之后指定。根据此处endwhile;的 Wordpress 文档,“此函数破坏了在自定义循环上使用的先前查询。应在循环之后调用函数以确保条件标签按预期工作。

于 2012-11-20T08:15:11.140 回答
0

出了什么问题the_post()。应该是$query->the_post();反而。

所以正确的循环是

<?php  
//...  
while ($query->have_posts()) : $query->the_post(); ?>

                <div id="forum-front" class="bbp-forum-front">
                    <h1 class="entry-title"><?php the_title(); ?></h1>
                    <div class="entry-content">

                        <?php //the_content(); ?>

                        <?php //bbp_get_template_part( 'content', 'archive-forum' ); ?>

                    </div>
                </div><!-- #forum-front -->

            <?php endwhile; ?>
于 2012-11-21T04:45:41.060 回答