2

我正在使用 wordpress 插件 - 'bbpress' 来使用论坛。以下代码来自文件

/projectname/wp-content/plugins/bbpress/templates/default/bbpress/loop-topics.php

现在论坛工作正常。但我需要添加自定义代码,以便根据日期、回复数和 ASC 或 DESC 顺序的字母顺序进行排序。如您所见,我在其中添加了以下代码块。

 $bbp_loop_args = array(
    'orderby' => 'date',
    'order' => 'DESC',
    );

我将这个 $bbp_loop_args 参数与“while()”一起发送。这是下面的完整代码。

<?php

/**
* Topics Loop
*
* @package bbPress
* @subpackage Theme
*/

?>

<?php do_action( 'bbp_template_before_topics_loop' ); ?>
<?php 
if(bbp_get_forum_topic_count()>0)
    {       

        $bbp_loop_args = array(
        'orderby' => 'date',
        'order' => 'DESC',
        );
        ?>
<ul id="bbp-forum-<?php bbp_forum_id(); ?>" class="bbp-topics">

<li class="bbp-header">

    <ul class="forum-titles">
        <li class="bbp-topic-title"><?php _e( 'Topic', 'bbpress' ); ?></li>
        <li class="bbp-topic-voice-count"><?php _e( 'Voices', 'bbpress' ); ?></li>
        <li class="bbp-topic-reply-count"><?php bbp_show_lead_topic() ? _e( 'Replies', 'bbpress' ) : _e( 'Posts', 'bbpress' ); ?></li>
        <li class="bbp-topic-freshness"><?php _e( 'Freshness', 'bbpress' ); ?></li>
    </ul>

</li>

<li class="bbp-body">

    <?php while ( bbp_topics($bbp_loop_args) ) : bbp_the_topic(); ?>

        <?php bbp_get_template_part( 'loop', 'single-topic' ); ?>

    <?php endwhile; ?>

</li>

<li class="bbp-footer">

    <div class="tr">
        <p>
            <span class="td colspan<?php echo ( bbp_is_user_home() && ( bbp_is_favorites() || bbp_is_subscriptions() ) ) ? '5' : '4'; ?>">&nbsp;</span>
        </p>
    </div><!-- .tr -->

</li>

</ul>
    <?php  } ?>
    <!-- #bbp-forum-<?php bbp_forum_id(); ?> -->

<?php do_action( 'bbp_template_after_topics_loop' ); ?>

但我不知道我在哪里做错了。论坛工作正常,但我传递的论点似乎不起作用,因此排序不起作用。谁能快速回复这个问题?谢谢。

4

2 回答 2

9

试试这个——用这个替换你的循环代码,

<li class="bbp-body">
    <?php if ( bbp_has_topics( $bbp_loop_args ) ) : ?>
        <?php while ( bbp_topics() ) : bbp_the_topic(); ?>

            <?php bbp_get_template_part( 'loop', 'single-topic' ); ?>

        <?php endwhile; ?>
    <?php endif;?>
</li>

这可能是工作...

主题的默认参数数组:--

$default = array(
    'post_type' => bbp_get_topic_post_type(), // Narrow query down to bbPress topics
    'post_parent' => $default_post_parent, // Forum ID
    'meta_key' => '_bbp_last_active_time', // Make sure topic has some last activity time
    'orderby' => 'meta_value', // 'meta_value', 'author', 'date', 'title', 'modified', 'parent', rand',
    'order' => 'DESC', // 'ASC', 'DESC'
    'posts_per_page' => bbp_get_topics_per_page(), // Topics per page
    'paged' => bbp_get_paged(), // Page Number
    's' => $default_topic_search, // Topic Search
    'show_stickies' => $default_show_stickies, // Ignore sticky topics?
    'max_num_pages' => false, // Maximum number of pages to show
);
于 2014-02-20T09:58:38.083 回答
4

无法发表评论,因为我的代表 < 50 所以这是第 2 部分作为答案:/

按回复数排序:

$bbp_loop_args = array(
    'meta_key' => '_bbp_reply_count',
    'orderby'  => 'meta_value_num'
    );
于 2014-02-20T21:06:11.417 回答