Reply To: Adding a subnav with new page content to the profile/activity page
I believe the above doesn’t work correctly because I am adding the new content as a subnav which by default tried to inherit the parent template (correct me if I’m wrong).
Here is what I came up with (this all goes in functions.php), it still needs fine tuning and testing (for example I broke pagination and commenting):
function my_test_setup_nav() {
global $bp;
$parent_slug = 'wall';
$child_slug = 'all';
//name, slug, screen, position, default subnav
bp_core_new_nav_item( array( 'name' => __( 'test' ), 'slug' => $parent_slug, 'screen_function' => 'my_profile_page_function_to_show_screen', 'position' => 40, 'default_subnav_slug' => 'test_sub' ) );
}
function my_profile_page_function_to_show_screen() {
//add title and content here - last is to call the members plugin.php template
add_action( 'bp_template_title', 'my_profile_page_function_to_show_screen_title' );
add_action( 'bp_template_content', 'my_profile_page_function_to_show_screen_content' );
bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
}
function my_profile_page_function_to_show_screen_title() {
echo 'something';
}
function my_profile_page_function_to_show_screen_content() {
global $activities_template;
$personal_activites = array();
$friends_activites = array();
$group_activites = array();
//Get friends Loop
do_action( 'bp_before_activity_loop' );
if ( bp_has_activities( bp_ajax_querystring( 'activity' )."&scope=friends") ) :
$friends_activites = $activities_template->activities;
endif;
do_action( 'bp_after_activity_loop' );
//Get personal Loop
do_action( 'bp_before_activity_loop' );
if ( bp_has_activities( bp_ajax_querystring( 'activity' )."&scope=just-me") ) :
$personal_activites = $activities_template->activities;
endif;
do_action( 'bp_after_activity_loop' );
//Get groups Loop
do_action( 'bp_before_activity_loop' );
if ( bp_has_activities( bp_ajax_querystring( 'activity' )."&scope=groups") ) :
$group_activites = $activities_template->activities;
endif;
do_action( 'bp_after_activity_loop' );
do_action( 'bp_before_member_activity_post_form' );
bp_get_template_part( 'activity/post-form' );
do_action( 'bp_after_member_activity_post_form' );
$activities_template->activities = array_merge($personal_activites,$group_activites,$friends_activites);
quickSort( $activities_template->activities );
?>
<?php do_action( 'bp_before_activity_loop' ); ?>
<?php /* Show pagination if JS is not enabled, since the "Load More" link will do nothing */ ?>
<noscript>
<div class="pagination">
<div class="pag-count"><?php bp_activity_pagination_count(); ?></div>
<div class="pagination-links"><?php bp_activity_pagination_links(); ?></div>
</div>
</noscript>
<?php if ( empty( $_POST['page'] ) ) : ?>
<ul id="activity-stream" class="activity-list item-list">
<?php endif; ?>
<?php while ( bp_activities() ) : bp_the_activity(); ?>
<?php bp_get_template_part( 'activity/entry' ); ?>
<?php endwhile; ?>
<?php if ( bp_activity_has_more_items() ) : ?>
<li class="load-more">
<a href="#more"><?php _e( 'Load More', 'buddypress' ); ?></a>
</li>
<?php endif; ?>
<?php if ( empty( $_POST['page'] ) ) : ?>
</ul>
<?php endif; ?>
<?php do_action( 'bp_after_activity_loop' ); ?>
<form action="" name="activity-loop-form" id="activity-loop-form" method="post">
<?php wp_nonce_field( 'activity_filter', '_wpnonce_activity_filter' ); ?>
</form>
<?php
}
add_action( 'bp_setup_nav', 'my_test_setup_nav' );
// Non-recurive Quicksort for an array of Person objects
// adapted from http://www.algorithmist.com/index.php/Quicksort_non-recursive.php
function quickSort( &$array )
{
$cur = 1;
$stack[1]['l'] = 0;
$stack[1]['r'] = count($array)-1;
do{
$l = $stack[$cur]['l'];
$r = $stack[$cur]['r'];
$cur--;
do{
$i = $l;
$j = $r;
$tmp = $array[(int)( ($l+$r)/2 )];
// partion the array in two parts.
// left from $tmp are with smaller values,
// right from $tmp are with bigger ones
do{
while( strtotime($array[$i]->date_recorded) > strtotime($tmp->date_recorded) )
$i++;
while( strtotime($tmp->date_recorded) > strtotime($array[$j]->date_recorded) )
$j--;
// swap elements from the two sides
if( $i <= $j){
$w = $array[$i];
$array[$i] = $array[$j];
$array[$j] = $w;
$i++;
$j--;
}
}while( $i <= $j );
if( $i < $r ){
$cur++;
$stack[$cur]['l'] = $i;
$stack[$cur]['r'] = $r;
}
$r = $j;
}while( $l < $r );
}while( $cur != 0 );
}
I’m sure there is a more elegant and seamless way to do it, and I will try to figure out exactly what that is. I’ll probably end up making templates for this to try and have cleaner code and stop the ajax bugs I created.
But for now, congratulations, you now have an aggregate news feed.