Skip to content

Instantly share code, notes, and snippets.

@ntwb
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ntwb/ca87b9b75a42215b2889 to your computer and use it in GitHub Desktop.
Save ntwb/ca87b9b75a42215b2889 to your computer and use it in GitHub Desktop.
bbPress - Random Single Topic - http://bbpress.org/forums/topic/random-topic-link/
<?php
/*
Plugin Name: bbPress - Random Single Topic
Plugin URI: https://gist.github.com/ntwb/ca87b9b75a42215b2889
Description: bbPress - Random Single Topic
Version: 0.1
Author: Stephen Edgar - Netweb
Author URI: http://netweb.com.au
*/
// bbPress - Random Single Topic
function ntwb_bbpress_random_single_topic() {
if ( bbp_has_topics( array( 'orderby' => 'rand', 'posts_per_page' => 1 ) ) ) {
while ( bbp_topics() ) : bbp_the_topic();
?>
<a class="bbp-topic-permalink" href="<?php bbp_topic_permalink(); ?>"><?php bbp_topic_title(); ?></a>
<?php
endwhile;
}
}
// Hook into action
add_action('bbp_template_before_lead_topic','ntwb_bbpress_random_single_topic');
// Add it as a shortcode [ntwb-bbpress-random-single-topic]
add_shortcode('ntwb-bbpress-random-single-topic', 'ntwb_bbpress_random_single_topic');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment