Skip to:
Content

BuddyPress.org

Opened 14 years ago

Closed 14 years ago

Last modified 8 years ago

#2427 closed enhancement (no action required)

Plugin: expanding bp_nav_items for WP 3.0

Reported by: mercime's profile mercime Owned by:
Milestone: 1.5 Priority: major
Severity: Version:
Component: Templates Keywords:
Cc:

Description

Finding a WP 3.0 solution to

  • auto exclude BP navigation in wp_list_pages to differentiate from "regular" WordPress Pages without needing to exclude page ID's of BP component/plugin Pages
  • plus being able to render only BP-dependent components with

and BP plugins which hook to this, <?php bp_nav_items() ?> template tag in second navbar or dropdown menu without needing to hardcode any or all BP navigation items

There are many instances where BP will be used not only for a stand-alone networking installation but added on as a feature in existing WP/MU installs used as CMS with around e.g. 20 - 220++ organized pages rendered in 8 parent pages via wp_list_pages.

In test install of WP 3.0 beta1 to RC version, BP components are rendered as Pages and get added into the list of "regular" pages via the wp_list_pages of the site and breaks layout. The proposed plugin e.g. bp_nav_items_reloaded plugin will automatically exclude the BP component Pages from wp_list_pages and auto include them in in bp_nav_items along with the BP-dependent plugin nav links which can be placed in second navbar or drop down of a regular Page.

For consideration.

Change History (9)

#1 @r-a-y
14 years ago

This should be quite easy.

I'm not using WP 3.0, but try these little functions in your theme's functions.php:

// filter to exclude BP pages from wp_list_pages() - don't use this as a template tag!
function bp_exclude_wp_list_pages( $exclude_array ) {
	global $current_blog;

	if ( defined( 'BP_ENABLE_MULTIBLOG' ) )
		$page_ids = get_blog_option( $current_blog->blog_id, 'bp-pages' );
	else
		$page_ids = get_blog_option( BP_ROOT_BLOG, 'bp-pages' );

	if ( empty( $page_ids ) )
		return $exclude_array;

	$exclude_merge = array_merge( $page_ids, $exclude_array );

	return $exclude_merge;
}
add_filter( 'wp_list_pages_excludes', 'bp_exclude_wp_list_pages' );


// template tag to list only BP pages
function bp_list_pages() {
	global $current_blog;

	if ( defined( 'BP_ENABLE_MULTIBLOG' ) )
		$page_ids = get_blog_option( $current_blog->blog_id, 'bp-pages' );
	else
		$page_ids = get_blog_option( BP_ROOT_BLOG, 'bp-pages' );

	if ( empty( $page_ids ) )
		return false;

	$page_ids_delimited = implode( ',', (array)$page_ids );		

	wp_list_pages( 'include=' . $page_ids_delimited );
}

#2 @mercime
14 years ago

@r-a-y Thank you for taking time to address this issue. Will be testing this out this week and report back. Cheers.

#3 follow-up: @mercime
14 years ago

@r-a-y, tested the code in WPMU 2.9.2 upgraded to WP 3.0 stable and BP trunk. No go in three different ways: in functions.php, in bp-custom.php nor in mu-plugins :-) What's interesting is that the code brought forth the "Activate" and "Register" page links in the menu.

#4 @r-a-y
14 years ago

I'll need to play around with this when I upgrade to BP trunk.

#5 in reply to: ↑ 3 @sbrajesh
14 years ago

Replying to mercime:

@r-a-y, tested the code in WPMU 2.9.2 upgraded to WP 3.0 stable and BP trunk. No go in three different ways: in functions.php, in bp-custom.php nor in mu-plugins :-) What's interesting is that the code brought forth the "Activate" and "Register" page links in the menu.

Hi Mercime,
On which revision of BP you are, I am on r3055 and r-a-y's code is working for me. btw, I am using wp3.0 in single wp mode

#6 @boonebgorges
14 years ago

Something along the lines of r-a-y's code should work against the trunk. Here's an easier way to get the bp-pages page ids:

$page_ids = bp_core_get_page_meta();

I don't think that anything like this filter belongs in the trunk, though. For themes that support it, the WP 3.0 menus make it easy to specify which links get shown in a menu. And anyone smart enough to use wp_list_pages() should be able to figure out a filter like the one that r-a-y gives above. Other thoughts?

#7 @DJPaul
14 years ago

  • Resolution set to invalid
  • Status changed from new to closed

I'm closing this as in trunk as you can now create a custom menu and put whatever items you want in.

#8 @mercime
13 years ago

  • Component changed from Core to Theme
  • Type changed from defect to enhancement

@DJPaul Yes I like those custom menus too :-) That's the answer for say, 20 regular Pages plus 5 BP component Pages in BP 1.3.

But for sites with e.g. 21 to 220 Pages not including the new BP 1.3 Pages, it's not an efficient method when those 21++220 Pages with Parent-Child-Child hierarchy and with already set Page Orders can just be rendered so easily and intuitively via wp_list_pages or wp_page_menu.

In the course of going the route or wp_nav_menus, I found a glitch in test XAMPP install with around 32 Pages including BP trunk component Pages. The wp_nav_menu limits to 16 items in this install. Searching in WP Trac for any similar issue gave me this http://core.trac.wordpress.org/ticket/14134. One solution:
`suhosin.post.max_vars = 5000
suhosin.request.max_vars = 5000`
Is adding minimum suhosin something we should add to BP Codex if the issue is not fixed by WP 3.2?

Note: Testing wp_nav_menu with the same number of Pages in webhost server did not give me any glitches, fortunately. It only gave me a headache moving each of 32 Pages to respective hierarchichal and ordered positions when these settings were already done in Page Add/Edit panel :-)

I might be overlooking something. The code given above to do so hasn't worked for me in another test install early this year. I will check it again with trunk sometime soon.

#9 @DJPaul
8 years ago

  • Component changed from Appearance - Template Parts to Templates
Note: See TracTickets for help on using tickets.