Skip to:
Content

BuddyPress.org

Opened 12 years ago

Closed 8 years ago

#4328 closed enhancement (fixed)

Using a WP custom page template for a BP component's page

Reported by: modemlooper's profile modemlooper Owned by:
Milestone: 2.2 Priority: normal
Severity: major Version: 1.5
Component: Core Keywords:
Cc: mercijavier@…

Description

I was trying to create a custom page template but no matter what BP is using the activity loop instead. If you do not have a posts loop on the page it seems to reject anything else. Check out images below of screen shots of the page and page template

Attachments (2)

page temp.png (55.5 KB) - added by modemlooper 12 years ago.
choosing page template in admin
the page template code.png (26.6 KB) - added by modemlooper 12 years ago.
page template code

Download all attachments as: .zip

Change History (17)

@modemlooper
12 years ago

choosing page template in admin

@modemlooper
12 years ago

page template code

#1 @modemlooper
12 years ago

link to the page showing the activity loop http://dev.taptappress.com/buzz

#2 @r-a-y
12 years ago

  • Keywords reporter-feedback added
  • Version changed from 1.5.6 to 1.5

Are you trying to override a BP component's directory page with a custom page template?

If so, you can't based on this. A workaround is just to modify the activity directory index template in your theme - /activity/index.php.

Update: I guess you could filter 'bp_activity_screen_index' and tell WP to use your custom page template if one exists. Sounds like a good enhancement!

Last edited 12 years ago by r-a-y (previous) (diff)

#3 @r-a-y
12 years ago

  • Summary changed from BP overrides page templates 1.5.6 to Using a WP custom page template for a BP component's page
  • Type changed from defect (bug) to enhancement

#4 @modemlooper
12 years ago

Ray, your suggestion would be a killer idea for theme developers to include custom template files that are choosable like page templates. +10,000

Ok so, on two installs I'm getting same thing but on another it's working as normal. I'm testing more to see if it's something specific. I think it's when BP is on a sub domain it's messing with WP page templates. I need to do another fresh test site on a sub domain to confirm. Sites on a url.com seem to be ok.

Last edited 12 years ago by modemlooper (previous) (diff)

#5 @r-a-y
12 years ago

  • Keywords dev-feedback added

I spent a little bit of time to implement this and it works!

Here's the code snippet:

/**
 * On the WP page dashboard, if you set a custom page template for a BP 
 * component page, let BP know of it and use it!
 */
function ray_use_custom_page_template_for_bp_component_index( $template ) {
	// see if a custom page template exists for the BP component page
	$custom_template = get_page_template_slug();
	
	// if no custom template, return the default one
	if ( empty( $custom_template ) )
		return $template;

	// return our custom page template; we strip the extension because bp_core_load_template() requires it
	return ( str_replace( '.php', '', $custom_template ) );
}
add_filter( 'bp_activity_screen_index',                  'ray_use_custom_page_template_for_bp_component_index' );
add_filter( 'bp_blogs_screen_index',                     'ray_use_custom_page_template_for_bp_component_index' );
add_filter( 'bp_members_screen_index',                   'ray_use_custom_page_template_for_bp_component_index' );
add_filter( 'bp_forums_template_directory_forums_setup', 'ray_use_custom_page_template_for_bp_component_index' );
add_filter( 'groups_template_directory_groups',          'ray_use_custom_page_template_for_bp_component_index' );

Core devs: Not sure where to put this in core. I was thinking of adding the function to bp-core-functions.php. Then, adding the applicable filter to each component's bp-COMPONENT-filters.php. Let me know what you think.

get_page_template_slug() does use a few DB queries though - get_post(), get_post_meta() - just something to think about.

The code snippet could be released as a tiny plugin as well.

#6 @DJPaul
12 years ago

  • Keywords dev-feedback removed
  • Milestone changed from Awaiting Review to Future Release

Not sure if we'll want/need to do this when we put theme compatibility into BP, but moving to the future release milestone for review at that point in time.

#7 @mercime
12 years ago

  • Cc mercijavier@… added

#8 @mercime
12 years ago

+1 for bp-default theme especially as many are using only bp-default child themes in their installs. I do :-)

#9 follow-up: @modemlooper
12 years ago

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

#10 @DJPaul
12 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

Not fixed yet as not committed into BuddyPress. Related ticket is #4639

#11 in reply to: ↑ 9 @johnjamesjacoby
12 years ago

Replying to modemlooper:
Please add a comment in the ticket when making changes to it, otherwise it's impossible to know what your intentions were at the time.

#12 @modemlooper
12 years ago

I figured that theme compat was fixing this, no?

#13 @r-a-y
10 years ago

  • Keywords reporter-feedback removed

I just closed #5686 as a duplicate.

I figured that theme compat was fixing this, no?

Theme compatibility does not address this. My code above works on bp-default installs.

However, imath's code in ticket:3741#comment:27 (the second part) would address this for theme compatibility.

#14 @boonebgorges
10 years ago

I like the idea of adding page template support. Obviously, this would only work for top-level templates. If we do, I don't think it's necessary to do it for bp-default style themes.

#15 @DJPaul
8 years ago

  • Milestone changed from Future Release to 2.2
  • Resolution set to fixed
  • Status changed from reopened to closed

This has been implemented sometime previous, circa 2.2.

Note: See TracTickets for help on using tickets.