WordPress: view the latest topics in bbPress

We have seen how the integrated kernel WordPress bbPress , for example, to use some function or share your WordPress theme. Now we will see the contraio, namely how to display the information in the bbPress forum home page of WordPress. To do this there are some plugins (some working and others not). Here we shall see how we write a - really - simple function that, in case, can be improved and perfected in all cases.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/ **
* View the latest forum threads from bbPress
*
* @ Author = undo =
* @ Date 11/09/2009
*
* @ Return
* /
bbpress_wp_get_last_topics function ($ limit = 10) {
global $ wpdb;

/ / Connect to database - change parameters with their
/ / Login to mysql dabase
$ Db_bbpress = new wpdb ('bbPress', 'bbPress', 'bbPress', 'localhost');
$ Query = "SELECT * FROM bb_posts JOIN ON bb_forums bb_posts.post_status = '0 'AND JOIN bb_topics bb_forums.forum_id bb_posts.forum_id = ON = bb_posts.topic_id bb_topics.topic_id bb_posts.post_time ORDER BY DESC LIMIT 0,". $ Limit;
$ = $ List_topics db_bbpress-> get_results ($ query);

foreach ($ list_topics as $ topic):?>
<div class="forum">

$topic -> topic_id ?> " title=" <?php echo $topic -> topic_title ?> " > <?php echo $topic -> topic_title ?> </a></h2> <h2> <a href = "/ forum / topic.php? id = <? php echo $ topic -> topic_id?>" title = "<? php echo $ topic -> topic_title?>"> <? php echo $ Topic -> topic_title?> </ a> </ h2>
word_cut_for_chars ( strip_tags ( $topic -> post_text , '<b><strong><i><u>' ) , 100 ) ?> </p> <p> <? php echo word_cut_for_chars ( strip_tags ($ topic -> post_text, '<b> <strong> <i> <u>'), 100)?> </ p>
</ Div>
; <? Php endforeach;
}

Some notes:

  • This example shows that the database bbPress is "outside", ie you can not use the same connection already made ​​available by the core of WordPress. However bbPress can be installed on the same database WordPress. In doing so the connection is not necessary but you can use the object directly (global) $wpdb
  • The link "/forum/..." refers to your installation path: Normally www.dominio.com/forum
  • The function word_cut_for_chars() cuts a string counting characters, find the source Very short snippet: PHP, cut into words, counting the characters

One Response to "WordPress: view the latest topics in bbPress"

  1. June 7, 2010 Mark :

    If I wanted to do the opposite as I do? I wish that EVERY post old and new WP had a duplicate on BB and vice versa.
    In the case of my blog is important enough that the final outputs are clear and understandable in a home but are then also tracked in order to entice the discussion forum (like film circles for instance).
    Thanks so much for the time you've stolen!
    I state that I'm pretty ignorant about PHP etc. but a copy / paste I find it great!

Leave a comment

TAG XHTML PERMITS: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> INSERTION CODE:
 <pre></pre> // blocco generico <code></code> // blocco generico [cc_actionscript][/cc_actionscript] // Actionscript [cc_actionscript3][/cc_actionscript3] // Actionscript 3 [cc_css][/cc_css] // CSS Style Sheet [cc_html][/cc_html] // HTML [cc_js][/cc_js] // Javascript [cc_objc][/cc_objc] // Objective-C [cc_php][/cc_objc] // PHP [cc_sql][/cc_sql] // SQL 


Stop SOPA