How to link to post or group

With the Attach Posts to Groups Extension, you can redirect Posts to the attached group automatically.

If you do not want to redirect the Post to the Group, you can link to the post from the group and back to the post.

There are 3 different ways how to do this.

Via ShortCodes

This is the shortcode to link to the attached group:

[buddyforms_link_to_group]
			

This is the shortcode to link to the attached post:

[buddyforms_link_to_post]
			

You can also use shortcodes in php with the do_shortcode function See the WordPress Codex for more information: http://codex.wordpress.org/Function_Reference/do_shortcode

Hook the Link

Link to the Attached Post

In this first example, we hook the post link after the Group Headder

add_action('bp_after_group_header', 'hook_post_permalink');<br>
			

In this example function "hook_post_permalink" I create the link to the Group attached Post. To get the Permalink I call the buddyforms_link_to_post function which will return the Post permalink.

function hook_post_permalink(){
    echo '<a href="' . buddyforms_link_to_post() . '">Link to Post</>';
}<br>
			

Link to the Attached Group

In this second example we hook the Group link after the Group Header

add_action('the_content', 'hook_group_permalink');<br>
			

In this example function "hook_group_permalink" I create the link to the Post attached Group. To get the Permalink I call the buddyforms_link_to_group function which will return the Group permalink.

function hook_group_permalink($content){
    return $content .= '<a href="' . buddyforms_link_to_group() . '">Link to Group</>';
}
			

In the Template

You can create the links in your template.

This tow functions will always return the permalink of the attached post/group if it exists

Link to the Attached Group

buddyforms_link_to_group()
			

Link to the Attached Post

buddyforms_link_to_post()
			

Still need help? Contact Us Contact Us