OfficeRoster Widget with PHP

When used with the Buying Buddy PHP class, the OfficeRoster widget can create permalinks for Agent Profile pages.

This method will require requires the Buying Buddy PHP API, htaccess file modifications and rewrite rules.

See the OfficeRoster widget for complete details on how this widget can be used - especially initial view and permalink options.
See Buying Buddy PHP Class and API for details on PHP support.

You must use the latest Buying Buddy Plugin JavaScript.
See installation instructions for details.

Overview

You will need to parse the Request URI in order to create the slug so the widget calls the correct URL to retrieve the right information.

Use a rewrite rule to send everything to one php page.

Instructions

NOTE: These URLs are built into links on the widget and must be followed

/team  (this page will show Offices but can be overwritten to show roster by default)
/team/office (this will show the Roster of users)
/team/ProfileName (this will show the User Profile)

1. Create a page for the OfficeRoster widget

This should be /team

2. Add Code to Designated Page

// Strip out "/team" to get remaining URI string
// You may need to remove trailing "/" or ".php" depending on your site URL structure
$str = str_replace("/team","",$_SERVER['REQUEST_URI']);
// If there is noting remaining, show the offices or roster as desired
if ( empty($str) ){
    // -  Use "roster" instead of "index" if you want 
    //    to show the user roster instead of the map with office locations by default
    // -  If the slug contains the word "office" then the page will be showing 
    //    the office roster (list of offices)
    //    Because of searching by name, first letter of last name and office_id 
    //    you want to be sure to append everything after the word office
    //    Some examples of what the $slug should look like: 
    //    roster, roster/last/c, roster/search/xxxx, roster/id/7
    
    $slug = "index"; 
} else if ( strpos($str,"office") !== false ){
    $slug = str_replace("/office","roster",$str);
    // Otherwise it is an agent profile
    // Example of $slug : agent/name/UserName
} else {
    $slug = "agent/name".$str;
}

// Add the optional $slug to the getWidget call
$brokersObj = $mbbObj->getWidget("MBBv3_OfficeRoster", array("filter" => "office:on+mapPin:blue"), $slug );

// Output the widget HTML
<div id="MBBv3_OfficeRoster" filter="office:on+mapPin:blue">
    <?=$brokersObj->html?>
</div>

Please contact us via the Help Desk if you need support for this function.

Joomla - 404 Special Notes

If you are seeing 404 errors when going to a user profile page (e.g. /team/bobsmith ) the following may assist.
However, please note that all systems are a little different and so this may need tailoring for your setup

Add the following rules in your .htaccess file to redirect to the agent profile page, and prevent indefinite looping on the team page.

Note: You must have !/ before team and the trailing / after team in the RewriteCond, as this tells the system to only run the code once and prevents the script from looping.

# REDIRECT FOR AGENT PERSONAL PAGE
RewriteCond %{REQUEST_URI} !/team/ [NC]
RewriteCond %{REQUEST_URI} !/team/office/ [NC]
RewriteRule ^team/(.*)?$ /team/$1 [R=301,NC,L]
# REDIRECT FOR ALL OTHER OFFICE LINKS
RewriteCond %{REQUEST_URI} !/team/office/ [NC]
RewriteRule ^team/office/(.*)?$ /team$1 [R=301,NC,L]
Updated on December 28, 2023

Was this article helpful?

Related Articles

Need Support?
Can't find the answer you're looking for?
Contact Support
Buying Buddy Support