Search

bbPress Showcase » WordPress Integration

Plug-in Idea: Show bbPress forum topic in Wordpress Loop?

RSS
  1. mrhoratio
    User has not uploaded an avatar

    junior member
    Joined: Apr '08
    Posts: 9

    offline

    Hey _ck_, I just noticed that bbPress now has a "promote to front page" functionality in the form of a "Stick to front" link in every topic. Here's a couple of threads on the bbPress site which discusses it:

    http://bbpress.org/forums/topic/stick-to-front-removes-topic-from-forum
    http://bbpress.org/forums/topic/categories-in-0901

    There's no support for Wordpress integration with this feature, but perhaps it will come in a future version.

    Posted 4 years ago #
  2. _ck_
    _ck_

    senior admin
    Joined: Jul '06
    Posts: 908

    offline

    No the idea was to make a special front page instead of the regular latest discussions that holds the promoted topics with custom summaries for what they are about, including their own RSS feed. It would replace the regular front page.

    This is a demo of the bbPress Signatures plugin!
    If you use my plugins, please considering donating to help continue their development.
    Posted 4 years ago #
  3. mrhoratio
    User has not uploaded an avatar

    junior member
    Joined: Apr '08
    Posts: 9

    offline

    Ah I see, that would be a great plugin.

    I was just now tinkering with the bbPress template to make a page that displays only Front Page stickies. Unfortunately, I couldn't figure out how to get it to paginate.

    Is there a way for bbPress to make an RSS of only Front Page stickies? That way I can use an RSS aggregator plugin to bring it into Wordpress. Or is there a way in Wordpress to query a bbPress database for all the front page stickies, bypassing RSS altogether?

    Posted 4 years ago #
  4. _ck_
    _ck_

    senior admin
    Joined: Jul '06
    Posts: 908

    offline

    You'd have to do a few plugin tricks but it could be done.

    Either I'd create a new custom view of just super-stickies (a front page sticky is called a super-sticky I think in bbPress) or I'd probably approach it by adding a variable to the end of a url (ie. forum.com/feed/?onlysticky=1 ) and hook bb_index.php and then "destroy" any regular posts in the list by unsetting $topics.

    ie. (and this is very rough, completely untested code)

    function onlysticky() {global $topics; if (isset($_GET['onlysticky'])) {unset($topics);}}
    add_action( 'bb_index.php', 'onlysticky');
    add_action( 'bb_rss.php', 'onlysticky' );

    Posted 4 years ago #
  5. mrhoratio
    User has not uploaded an avatar

    junior member
    Joined: Apr '08
    Posts: 9

    offline

    I tried unsetting $topics, but it just removed all of the topics from the page, since super stickies are also topics.

    I tried another approach and was able to retrieve the list of super stickies by putting this code in before a bbPress loop:

    $topics = $bbdb->get_results("SELECT * FROM $bbdb->topics WHERE topic_start_time BETWEEN $startdate AND $enddate ORDER BY topic_start_time DESC");

    I was also able to get stickies within a specific date range:

    $startdate="20080500223740";
    $enddate="20080502223740";
    
    $topics = $bbdb->get_results("SELECT * FROM $bbdb->topics WHERE topic_sticky = 2 AND topic_start_time BETWEEN $startdate AND $enddate ORDER BY topic_start_time DESC");

    This has a couple of issues:

    1. Query doesn't retrieve the topic's first entry, just topic title.
    2. Pagination is a little weird and doesn't respect what you have set for "Items per page" bbPress admin.

    I'll try to see if I can work these out.

    After that, the next step I want to do is to figure out how to run this query within Wordpress. Then, map the topic structure to a post structure (ie "topic_title" becomes "post_title"). Then, merge the query into a Wordpress loop. I suspect there will be pagination issues also in Wordpress. But one step at a time.

    Posted 4 years ago #
  6. mrhoratio
    User has not uploaded an avatar

    junior member
    Joined: Apr '08
    Posts: 9

    offline

    Looks like I've got something working. The basic idea is to retrieve topics from bbPress tables and merge them into an array of Wordpress posts, which can then be turned into a custom Loop using foreach.

    The only issue is that the number of posts per page won't match the "Blog pages show at most" in your admin settings, if there are retrieved bbPress topics on that page. Here's what the code looks like:


    <?php

    //Put Wordpress posts into an array;
    $wp_posts = $posts;

    if (!is_single()){

    //Retrieve first post of previous page (we need this post's date to query bbPress topics
    $offset=$paged*$posts_per_page+$posts_per_page;
    $first_post_of_previous_page = get_posts('numberposts=1&offset='.$offset);

    //First set the start and end dates to limit the query to the bbPress table
    $startdate=(date('YmdHis',strtotime($first_post_of_previous_page[0]->post_date_gmt)));
    $enddate=(date('YmdHis',strtotime($wp_posts[0]->post_date_gmt)));

    //Retrieve "Super Sticky" topics from bbPress tables.
    //This assumes your bbPress and Wordpress tables are in the same database.
    $bb_topics = $wpdb->get_results("SELECT * FROM bb_topics WHERE topic_sticky = 2 AND topic_start_time BETWEEN $startdate AND $enddate ORDER BY topic_start_time DESC");

    //Map bbPress topics to WordPress posts structure.
    foreach($bb_topics as $bb_topic){
    $bb_first_post = $wpdb->get_results("SELECT post_text FROM bb_posts WHERE post_position = '1' AND topic_id = $bb_topic->topic_id", ARRAY_A);
    $bb_post->ID = "00000".$bb_topic->topic_id;
    $bb_post->post_author = $bb_topic->topic_poster;
    $bb_post->post_date = $bb_topic->topic_start_time;
    $bb_post->post_content = $bb_first_post[0][post_text];
    $bb_post->post_title = $bb_topic->topic_title;
    $bb_post->post_status = "publish";
    $bb_post->comment_status = "open";
    $bb_post->ping_status = $bb_topic->post_id;
    $bb_post->post_name = "forums/topic/".$bb_topic->topic_slug;
    $bb_post->post_type = "post";
    $bb_post->comment_count = $bb_topic->topic_posts-1;

    //add bbPress topic to Wordpress posts array.
    $wp_posts[] = $bb_post;

    };

    //Create function to sort array of posts by date
    function compare($x, $y){
    if ( $x->post_date == $y->post_date )
    return 0;
    else if ( $x->post_date < $y->post_date )
    return 1;
    else
    return -1;
    }

    //Sort array
    usort($wp_posts,'compare');
    }

    ?>

    Posted 4 years ago #
  7. exchequer598
    exchequer598

    new member
    Joined: Apr '08
    Posts: 3

    offline

    I'd like to implement this feature too! Have you got it to work? I'm sorry, but I'm a bit new with all this. Please help. Thanks!

    Posted 3 years ago #
  8. yesanswer
    User has not uploaded an avatar

    new member
    Joined: Jul '09
    Posts: 2

    offline

    hi
    if i puplish my feed on bbpress, and i add many text for example in 10 min, can google take it for spamm?

    Posted 2 years ago #

RSS feed for this topic

Post a reply to “Plug-in Idea: Show bbPress forum topic in Wordpress Loop?”

You must log in to post.

keep _ck_ coding >> donate $5 <<     Theme Switcher:
28 users online from in the past 30 minutes. 12 bots 16 guests
7,442 views today 8,426 yesterday 16,043 peak. Most at once 50 today 62 yesterday 131 peak. Visited today: Amylawrence, guava, JeffreyCasivant, wigbuy123, gdfddfs, nandao, _ck_, summerfortun
2,288 posts in 394 topics over 66 months by 430 of 2,167 members. Latest: watchessaleus, wigbuy123, JeffreyCasivant