How-To: Add a directory page to your component
for a jobboard component I’m writing at the moment I needed a directory, just like the members or blogs directory. It took me a while to figure out how to get that page to display, so I thought I’d share what I ound out.
This little mini tutorial assumes you have a basic understanding of how a component is structured. If not, the skeleton component is an excellent starting point and I’d suggest you have a look through that first, at least the main plugin file.
The first thing to do is register our component as a root component, which means that you have pages outside your normal /members/username/ path. The way I have set the component up is that every group gets their very own jobboard, using the groups api. Then I have a directory page where all the jobs from all groups get collected and displayed and this page I want to show at http://yourdomain.com/jobboard/. That makes my component a root component.
I register it using this function, which resides in the main plugin file:
bp_core_add_root_component( JOBBOARD_SLUG );
add_action( 'plugins_loaded', 'jobboard_setup_root_component', 2 );
Then, directly after it, I load the template:
if ( $bp->current_component == $bp->jobboard->slug )
$bp->is_directory = true;
do_action( 'bp_core_action_directory_jobboard' );
bp_core_load_template( apply_filters( 'jb_directory_jobboard', 'directories/jobboard/index' ) );
add_action( 'wp', 'jb_directory_jobboard', 2 );
In my theme folder I have added another folder directories/jobboard. In this folder I then put the index.php and the jobs-loop.php files that hold the actual HTML code for the directory page.
And that’s about it.
You must be logged in to reply to this topic.