Browsing the blog archivesfor the day Friday, July 2nd, 2010.

Daily Tip: How to Exclude a Group From the Loop in BuddyPress

Internet Marketing

One sure fire way to exclude groups from the loop in BuddyPress is to set them as Private or Hidden in the admin settings. However, if you need the group to be visible in the directory but not in a particular widget, then you’ll have to use a little hack for now.

One example would be if you’re using a group as a shell for a “global forum” and you want to exclude that group from a widget that displays popular groups. BuddyPress documentation for custom group loops doesn’t include a parameter for excluding particular groups, so here’s how you can do it:

<?php while ( bp_groups() ) : bp_the_group();  if(bp_get_group_name() != 'My Group' ) : ?>

Replace ‘My Group’ with the group name that you want to exclude. Also, don’t forget to add an endif; right before the endwhile;

<?php endif; ?>

Many thanks to nahummadrid and r-a-y at the BuddyPress forums for this quick hack.

Post to Twitter Tweet This Post

No Comments

BuddyPress Hack to Add a Syntax Highlighter to Group Forums

Internet Marketing

Have you been wishing for an easy way to add syntax highlighting to your BuddyPress group forums? Now you can and it will only take you three minutes to hook it up. This hack was posted in the BuddyPress support forums by Rich Fuller, a prolific BuddyPress hacker and plugin developer whose blog is definitely subscription worthy. You can also see a live demo on his website.

How to Add a Syntax Highlighter to BuddyPress Group Forums

Step 1: Download SyntaxHighlighter Evolved

Install this plugin as you normally would. You’ll notice that it will only work for posts and pages. There’s just one more step to get it working with BuddyPress. Also, you need to be using BuddyPress version 1.2.4.1 or higher for this to work.

Add the Filters to syntaxhighlighter.php

add_filter( 'bp_get_the_topic_post_content', array(&$this, 'parse_shortcodes'), 7 );
add_filter( 'group_forum_post_text_before_save', array(&$this, 'encode_shortcode_contents_slashed'), 1 );
add_filter( 'group_forum_topic_text_before_save', array(&$this, 'encode_shortcode_contents_slashed'), 1 );
add_filter( 'bp_get_the_topic_text', array(&$this, 'decode_shortcode_contents'), 1 );
add_filter( 'bp_get_the_topic_post_edit_text', array(&$this, 'decode_shortcode_contents'), 1 );

You should add these statements in the file right after you see this:

add_filter( 'the_content', array(&$this, 'parse_shortcodes'), 7 );

Re-upload the file and now you’ll find that you can post code much more easily in the forums.

Now… if we could only get this added to the support forums at BuddyPress.org. ;) Here are five reasons why it’s a good idea to add a syntax highlighter at the BuddyPress forums or any other developer-centric site for that matter:

  1. Adding a syntax highlighter will eliminate a lot of errors people have with copying and pasting format issues.
  2. Developers will enjoy helping others more.
  3. It will significantly improve readability in the forums.
  4. It will make the forums more user-friendly and efficient so that people can find help faster.
  5. People will love it!

Feel free to add to this list in the comments below. :)

Post to Twitter Tweet This Post

No Comments