Ok, I have sort of figured this out myself, however it feels a little ‘hacky’ as I would have thought BP has a built in function to determine if it is the ‘main page’ of a users profile.
This is what I added to home.php, where the if else statements for the different template parts are:
$host = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
$userID = bp_displayed_user_id();
$userURL = bp_core_get_username($userID);
$testURL = $_SERVER['SERVER_NAME'].'/members/'. $userURL . '/';
//echo($host); /*Just to check*/
//echo($testURL); /*Just to check*/
if ( $host == $testURL ) :
bp_get_template_part( 'members/single/profile/profile-loop' );
This appears to accurately check if you are on the ‘main’ user page and then displays the profile template.
If there is a better way then please do let me know.
🙂 did you check the BP codex before embarking on above?
The docs is first port of call, we attempt to document as much as possible there on an ongoing basis, some pages are undergoing re-freshing & updating but still provide useful reference like this page:
Template Tag Reference
Where you might try bp_is_directory()
Or scan through bp-core-template.php in the core files where you’ll find reference to: bp_is_members_directory()
which actually is a very simple check to see if !bp_is_user() && bp_is_members_component() the difference remaining can only be the members main directory.
Generally BP is well specified for template tags and ‘is’ function checks.
@hnla – Hi Hugo. Thanks for answering. I think my question may not be clear and some terms are getting confused with others. The tags you describe above are for the members directory aren’t they?
For example, this would be located at example.com/members/. This is not the page I need to check for. I need to check for the main page of a members profile, e.g. example.com/members/exampleuser/. All of the other pages seem to have a tag to check for them, except this page.
Also, this needs to be for the main page of any profile, not just the logged in user, e.g. bp_is_home.
Ah oh, slightly harder possibly, try checking through the available tags though, something is probably achievable that is simpler than your initial attempt.
@hnla – yes it’s more complicated than it first seems. What I have works, just doubt it is the most efficient. Hopefully someone that has had to deal with this has a better solution that mine.