如何将参数传递给wordpress插件中的bbp_topics() - 'bbpress'

use*_*279 2 wordpress bbpress wordpress-plugin

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

/projectname/wp-content/plugins/bbpress/templates/default/bbpress/loop-topics.php
Run Code Online (Sandbox Code Playgroud)

现在论坛工作正常.但我需要添加自定义代码,以便根据日期,回复数量以及按ASC或DESC顺序的字母顺序进行排序.所以你可以看到我在那里添加了以下代码块.

 $bbp_loop_args = array(
    'orderby' => 'date',
    'order' => 'DESC',
    );
Run Code Online (Sandbox Code Playgroud)

这个$ 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' ); ?>
Run Code Online (Sandbox Code Playgroud)

但我不知道我在哪里做错了.该论坛工作正常,但我通过的论点似乎没有工作,因此排序不起作用.任何人都可以快速回答这个问题吗?谢谢.

Aks*_*dar 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>
Run Code Online (Sandbox Code Playgroud)

这可能是工作......

主题的默认参数数组: -

$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
);
Run Code Online (Sandbox Code Playgroud)