Javascript recursion example

Everyone loves(or should i say ‘gets intimidated by’?) Recursion. But it can be confusing to begin with. So here’s an example of recursion ( in javascript ) to show how recursion can be used to solve real problems in real projects ;) . The code below is an altered code from one of my projects. Although its in javascript, the basic principle is same and can be easily reproduced in any other language of your choice.

Hope it helps..

bbPress Tag Cloud Widget

A very small wordpress plugin. If you’ve been using bbPress plugin, you know that it provides a shortcode to display the topics-tag-cloud. I’ve wrapped that into a small widget, so one can just easily display the tag cloud wherever required with just drag-and-drop.

You can download the plugin form its github repository.
**Note: Github adds the word ‘-master’ into the plugin’s folder name, so uploading the zip file bbpress-tagcloud-widget-master.zip (downloaded from github) directly to install the plugin won’t work. So, just rename the zip file to bbpress-tagcloud-widget.zip.

That’s it here.

bbPress loading more topics with ajax

Created a plugin which allows you to add one ‘load more’ button on your bbPress topics archive. And obviously, that button click loads more topics and appends it at the end of the topics list.

The plugin can be loaded from here.

You can use it alongside the pagination. The plugin internally loads the same template files to display new topics, so it integrates with your existing theme without any extra effort.

Once you’ve installed and activated the plugin. You need to add 2-3 lines of code in your template file. The file that we will be editing is loop-topics.php. If you’ve not done already, create a folder inside your active theme, and name it as ‘bbpress’, then open the bbPress plugin folder, copy the file templates/default/bbpress/loop-topics.php and paste it inside the new folder that you created in your theme.
Open the file loop-topics.php and look for

<li class="bbp-body" >

An unaltered file will have the following code in that region

<li>

	<?php while ( bbp_topics() ) : bbp_the_topic(); ?>

		<?php bbp_get_template_part( 'loop', 'single-topic' ); ?>

	<?php endwhile; ?>

</li>

We need to add the code for the ‘load-more’ button there. The code that we need to add is:

<?php if( function_exists( 'bbpresslmt_loadmore_button' ) ): ?>
	<?php bbpresslmt_loadmore_button(); ?>
<?php endif; ?>

So after adding this code, our updated file should contain:

<li>

	<?php while ( bbp_topics() ) : bbp_the_topic(); ?>

		<?php bbp_get_template_part( 'loop', 'single-topic' ); ?>

	<?php endwhile; ?>

	<?php if( function_exists( 'bbpresslmt_loadmore_button' ) ): ?>
		<?php bbpresslmt_loadmore_button(); ?>
	<?php endif; ?>

</li>

That’s all we need to do. If you are viewing topics inside any forum, then topics from inside that forum is loaded. If you are viewing all topics list, all topics are loaded. So no configuration required on that part.

Drop in your comments for any issues with the plugin or any other feedback.