Skip to:
Content
Pages
Categories
Search
Top
Bottom

Custom Loops for Forum Topics

Viewing 20 replies - 1 through 20 (of 20 total)

  • Burt Adsit
    Participant

    @burtadsit

    Howdy, yes there is. It’s just not documented in the codex. Works the same though.

    See: /buddypress/bp-forums/bp-forums-templatetags.php

    @Burt

    Thanks for the reference. Are you pointing to bp_has_topics() function?

    That function needs a Forum ID and I want to instead pull latest 5 topics from the whole Forum. Is there any other function I am missing or would you suggest any workarounds?


    Burt Adsit
    Participant

    @burtadsit

    Nothing like that built into bp that I’m aware of. Somebody else wanted to do this also. They tried using Sam’s bbPress Live widget. The problem is that bp uses the bbpress live widget underneath for communications with bbpress. Conflicts ensued. I don’t have any easy solutions for you.

    Oh i see, I wont be using that widget then.

    Is there a way to get all forum IDs from BBPress so as to fetch posts from forums and sub-forums using bp_has_topics() function.


    Burt Adsit
    Participant

    @burtadsit

    There sure is. Kinda.

    $forums = bp_forums_get_forum();
    if ($forums){
    foreach ($forums as $f){
    .. do something with each forum like..
    $topics = bp_forums_get_topics($f['forum_id'], 5);
    .. do something with each topic ..
    }
    }

    bp_forums_get_forum() returns bbpress forum records. Same info as in the bb_forums table.

    See:

    /bbpress/xmlrpc.php

    /buddypress/bp-forums.php

    /buddypress/bp-forums/bp-forums-bbpress-live.php

    /buddypress/bp-forums/bp-forums-templatetags.php

    The BP_Forums_Template_Forum template loop class iterates over one specific forum.

    @Burt

    Thanks a lot for the function reference.


    Burt Adsit
    Participant

    @burtadsit

    You betcha. Get your template up and running then?


    Kunal17
    Participant

    @kunal17

    I had asked about this earlier but I have still not found the solution. Please post if you have one. Thanks!


    Windhamdavid
    Participant

    @windhamdavid

    that someone was me – https://buddypress.org/forums/topic.php?id=2893 what I had noted is that sam’s plugins is essentially the same as bp-forums-bbpress-live.php and the only answer (at this point) is to manually construct the bp_forums_get_forum() as you’ve suggested. the problem I was incurring previously was avoiding having to use the forum ID as an argument – when set to null it returns the most recent topics. https://trac.buddypress.org/ticket/375

    Yes I got my template running just fine.

    Here is the code I use to show 5 recent topics across forum:

    $topics = bp_forums_get_topics(0, 5);

    if ($topics)
    {
    foreach ($topics as $topic)
    {
    print '
    <div class="home-box-item">
    <a class="home-box-item-link" href="' . $topic['topic_uri'] . '">' . $topic['topic_title'] . '</a>
    by ' . $topic['topic_poster_display_name'] . '
    Freshness: ' . $topic['topic_time_since'] . '
    Posts: ' . $topic['topic_posts'] . '
    </div>
    ';
    }
    }
    else
    {
    print '<p>No topics found.</p>';
    }

    If you want to show topics from a specific forum then you can pass the forum ID parameter like this:

    $topics = bp_forums_get_topics(5, 5);<br />

    PS: Sorry for late reply.


    Kunal17
    Participant

    @kunal17

    Hi Milan,

    Thanks for the code. Where would I paste this code to allow me to show the 5 topics on my default buddypress home theme (guessing I would have to create a widget?)

    Kunal,

    You can put the code anywhere outside of widget if…else block.

    Kunal,

    Add my code after the following line in home.php of BBP Home theme:

    <div id="right-column">

    It should get you started.


    Kunal17
    Participant

    @kunal17

    Great. Ill try that. Thanks for your help Milan.


    Kunal17
    Participant

    @kunal17

    The code works perfectly. However, I want to use it in a widget (so that it shows up in the middle of my widget filled right column bar not the top or bottom. Any thoughts on how to go about doing that?


    r-a-y
    Keymaster

    @r-a-y

    Kunal17, you could potentially use the PHP Code Widget Plugin by Otto to paste that PHP snippet by Milan in there.

    https://wordpress.org/extend/plugins/php-code-widget/


    Kunal17
    Participant

    @kunal17

    Thanks ray. Ill try that out. Any idea if its compatible with WPMU?

    I think displaying group topics in various forms should be part of the core BP widgets as it really helps pull the community into discussions. Ill check if in the trac already or else submit it.


    Kunal17
    Participant

    @kunal17

    The above code link to the posts in the bbpress forums. Is there a way to modify it to take you into the group view instead?

    I want to restrict access to the forums directly and only want people to use it through the groups.


    slicktig1
    Participant

    @slicktig1

    Hi,Milan suggested code is not working on latest buddypress install. it is giving following fatal error

    Fatal error: Call to undefined function bp_forums_get_topics()

    Please suggest the alternative if any. thanks.

    I’m getting the same error as slicktig1.

    Anybody have an *updated* method of displaying a loop of latest forum topics from across all groups? Need to place this loop on my home page.

Viewing 20 replies - 1 through 20 (of 20 total)
  • The topic ‘Custom Loops for Forum Topics’ is closed to new replies.
Skip to toolbar