如何在bbPress(WordPress+bbPress插件)中创建自定义嵌套循环

时间:2011-02-27 作者:janoChen

以下是Wordpress帖子的处理方式:

   $my_query = new WP_Query( "cat=3" );
   if ( $my_query->have_posts() ) { 
       while ( $my_query->have_posts() ) { 
           $my_query->the_post();
           the_content();
       }
   }
   wp_reset_postdata();
我想知道如何在bbPress中做到这一点(比如,列出主题)。

2 个回复
最合适的回答,由SO网友:Bainternet 整理而成

bbpress有自己的查询类,名为BB_Query()

并接受:

    $ints = array(
            \'page\',     // Defaults to global or number in URI
            \'per_page\', // Defaults to page_topics
            \'tag_id\',   // one tag ID
            \'favorites\' // one user ID
        );

    $parse_ints = array(
        // Both
        \'post_id\',
        \'topic_id\',
        \'forum_id\',

        // Topics
        \'topic_author_id\',
        \'post_count\',
        \'tag_count\',

        // Posts
        \'post_author_id\',
        \'position\'
    );

    $dates = array(
        \'started\',  // topic
        \'updated\',  // topic
        \'posted\'    // post
    );

    $others = array(
        // Both
        \'topic\',    // one topic name
        \'forum\',    // one forum name
        \'tag\',      // one tag name

        // Topics
        \'topic_author\', // one username
        \'topic_status\', // *normal, deleted, all, parse_int ( and - )
        \'open\',         // *all, yes = open, no = closed, parse_int ( and - )
        \'sticky\',       // *all, no = normal, forum, super = front, parse_int ( and - )
        \'meta_key\',     // one meta_key ( and - )
        \'meta_value\',   // range
        \'topic_title\',  // LIKE search.  Understands "doublequoted strings"
        \'search\',       // generic search: topic_title OR post_text
                        // Can ONLY be used in a topic query
                        // Returns additional search_score and (concatenated) post_text columns

        // Posts
        \'post_author\',  // one username
        \'post_status\',  // *noraml, deleted, all, parse_int ( and - )
        \'post_text\',    // FULLTEXT search
                        // Returns additional search_score column (and (concatenated) post_text column if topic query)
        \'poster_ip\',    // one IPv4 address

        // SQL
        \'index_hint\',   // A full index hint using valid index hint syntax, can be multiple hints an array
        \'order_by\',     // fieldname
        \'order\',        // *DESC, ASC
        \'count\',        // *false = none, true = COUNT(*), found_rows = FOUND_ROWS()
        \'_join_type\',   // not implemented: For benchmarking only.  Will disappear. join (1 query), in (2 queries)



// Utility
//          \'append_meta\',  // *true, false: topics only
//          \'cache_users\',  // *true, false
//          \'cache_topics,  // *true, false: posts only
//          \'post_id_only\', // true, *false: this query is only returning post IDs
            \'cache_posts\'    // not implemented: none, first, last
        );

SO网友:John James Jacoby

@janoChen——同样的方法也可以用来获取bbPress论坛/主题/回复,还有一些内置函数可以充当它们的包装函数。

如果您可以回复您想要获取的信息,我可以向您展示如何构建查询。(即,您需要14个最新的公共主题,您需要用户id 7的25个最新回复,等等。)

结束

相关推荐

WordPress与BBPress的无缝集成

我在域名上有一个WordPress网站。com和BBPress安装在域中。com/子文件夹wp站点有一个指向论坛的菜单项,我希望两者之间的标题相同,以便它们可以导航回主站点。我该怎么做?谢谢