【问题标题】:how to pass parameters to bbp_topics() in wordpress plugin- 'bbpress'如何在 wordpress 插件中将参数传递给 bbp_topics() - 'bbpress'
【发布时间】:2014-03-21 03:33:29
【问题描述】:

我正在使用 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' ); ?>

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

【问题讨论】:

    标签: wordpress bbpress


    【解决方案1】:

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

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

    【讨论】:

    • @Akshya - 还有一件事。你能告诉如何订购 - “回复数”。我的意思是,如果 DESC,回复率较高的帖子将排在第一位。那么我必须在该数组中传递什么 $bbp_loop_args - for 'orderby' value ?为了按字母顺序排列主题,我必须通过什么?
    • 我不知道Number of replies,但我在答案中添加了默认参数...
    • 谢谢。它真的很有帮助。
    【解决方案2】:

    无法发表评论,因为我的代表

    按回复数排序:

    $bbp_loop_args = array(
        'meta_key' => '_bbp_reply_count',
        'orderby'  => 'meta_value_num'
        );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-08-19
      • 1970-01-01
      • 2016-11-20
      • 1970-01-01
      • 2013-09-27
      • 2011-07-06
      • 2023-04-01
      相关资源
      最近更新 更多