Reply To: showing topics from separate sites – need formatting help
Hi Robin. I made another improvement and added some comments. I noticed that, no matter where I inserted the shortcode, the topics displayed at the top of the content. After some searching I learned why – functions need to return a string. So I found an easy wordpress solution. I also simplified the shortcode, and removed the add_action line at the bottom as it was not doing anything. Here is the updated code:
add_shortcode( 'recent-bbpress-topics', 'recent_bbpress_topics' );
// Add Recent Topics to BBPress from separate site within WP Multisite
function recent_bbpress_topics($attr) {
//Switch to the blog where the bbpress topics are located
switch_to_blog($attr['id']);
//this, along with $response variable below, allows for display within content - without these, shortcode will display topics at top of content
ob_start();
if ( bbp_has_topics( array( 'author' => 0, 'show_stickies' => false, 'order' => 'DESC', 'post_parent' => 'any', 'posts_per_page' => 9 ) ) ) { ?>
<?php bbp_get_template_part( 'bbpress/loop', 'topics' );
//restore the current blog to maintain formatting
restore_current_blog();
}
//this, along with ob_start(); above, allows for display within content, instead of at the top of the content/page
$response = ob_get_contents();
ob_end_clean();
return $response;
}