Add a new Tab in the listing detail page
It doesn't get easier than this...
One of the most frequent questions we get, about customizing GeoDirectory, is how to add a new tab for custom content (like data from another plugin) in the listings detail page.
Adding a Tab from the backend is possible for GD custom fields and fieldsets, but if you want to show anything more advanced, please use the example coe below.
This is very easy and you can proceed like this:
To add a new tab labelled “New Tab” add the following code inside your active theme’s functions.php file.
[php]
add_filter(‘geodir_detail_page_tab_list_extend’, ‘geodir_detail_page_tab_list_extend’) ;
function geodir_detail_page_tab_list_extend($tab_array) {
$tab_array[‘my_new_tab’] = array(
‘heading_text’ => __(‘New Tab’,GEODIRECTORY_TEXTDOMAIN),
‘is_active_tab’ => false,
‘is_display’ => apply_filters(‘geodir_detail_page_tab_is_display’, true,’my_new_tab’),
‘tab_content’ => ”);
return $tab_array ; }
[/php]
To show your custom content inside the tab, please add the following code inside your active theme’s functions.php file.
[php]
add_action(‘geodir_after_tab_content’ ,’geodir_my_new_tab_content’);
function geodir_my_new_tab_content($tab_index)
{
if($tab_index ==’my_new_tab’)
{echo "Hello world!!";}
}[/php]
In this case we are simply showing the “Hello World!!” text. Instead of that you can add any code you want, like a shortcode, custom fields or any function to output other plugins’ content.
This will add the “New Tab” to all other custom post types you may have (Should you have the Events or the Custom Post Type addons installed).
If you wish to add a New Tab only to one custom post type, let’s say Events, you would have to slightly modify the 1st code snippet like in the example below.
[php]
add_filter(‘geodir_detail_page_tab_list_extend’, ‘geodir_detail_page_tab_list_extend’);
function geodir_detail_page_tab_list_extend($tab_array) {
if ( ‘gd_event’ == get_post_type() )
$tab_array[‘my_new_tab’] = array(
‘heading_text’ => __(‘New Tab’,GEODIRECTORY_TEXTDOMAIN),
‘is_active_tab’ => false,
‘is_display’ => apply_filters(‘geodir_detail_page_tab_is_display’, true,’my_new_tab’),
‘tab_content’ => ”);
return $tab_array ; }
[/php]
Developers you may be interested in reading more about this filter here :
geodir_detail_page_tab_list_extend
If you want to explore the function that builds and returns the list of available tabs as an array,.you can look here:
We will go through this function in a future post about altering tabs order.
Did you use this function to create a more complex and awesome customization on your Directory. If you care about sharing it, let us know in the content and we will extend this post with your suggestions!
Peter Munton
Hi Paolo I would like to add a short code to my new tab but this would be different in each place ie “[mbhi_hours location=”your location name”] ” where “your location name” would be different for each place?
paolo
Hi Peter,
please ask for support in the forum: https://wpgeodirectory.com/support/
Thanks
Alex
I also have an other question, but I did not see where to post it…
How can I exclude the normal posts / pages from the search result searching in the listing / directory?
If I search in the directory : http://hr.fulmina.org/?geodir_search=1&stype=gd_place&s=education&snear=&sgeo_lat=&sgeo_lon=
The normal posts form WordPress also show up and I would like to disable that.
Thanks for all,
Alex
paolo
That’s probably caused by a conflicting plugin.
Please submit any support question you may have in our support forum: https://wpgeodirectory.com/support/.
A team of specialists will be more than happy to assist you.
Thank you,
Alex
Hi Paolo,
OK, I will try that and tell you about it later.
Thanks for your quick answer 😉
Alex
Alex
Hi,
Could someone please just add how to show up an existing field / new field in the new tab created?
What’s the php code?
Thanks
Alex
paolo
there are 2 ways:
1) < ?php global $post; echo $post->custom_filed_key; //example $post->post_address
?>
or similar to WP custom field
2) < ?php echo geodir_get_post_meta( $post->ID, ‘custom_field_key_goes_here’, true ); ?>
Hope this helps,
Thanks
MJJ Dam
Hi,
Is it possible to integrate buddypress compliments into a new listings tab?
And where is the best place on the forum to post questions about the BuddyPress Compliments?
Regards,
Matthijs
paolo
Hi,
no it isn’t, that plugin is made for buddypress profiles, not for listings.
Thanks