Custom Tabs on Detail Site only at specific Custom Post Type
This topic contains 7 replies, has 3 voices, and was last updated by thomaskhom 10 years, 7 months ago.
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket-
AuthorPosts
-
August 1, 2014 at 9:21 am #10620
Hi @ all
i added custom tabs on the detail Site Code is below. My question how i need to modify the code to show the tabs only at detail Site from an specific custom post type. Example the Customs Tabs should by shown only at hotel listings detail pages.
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['sportaktiv_tab'] = array( 'heading_text' => __('SPORTaktiv',GEODIRECTORY_TEXTDOMAIN), 'is_active_tab' => false, 'is_display' => apply_filters('geodir_detail_page_tab_is_display', true, 'sportaktiv_tab'), 'tab_content' => '' ); $tab_array['routen_tab'] = array( 'heading_text' => __('Routen',GEODIRECTORY_TEXTDOMAIN), 'is_active_tab' => false, 'is_display' => apply_filters('geodir_detail_page_tab_is_display', true, 'routen_tab'), 'tab_content' => '' ); $tab_array['sportdetails_tab'] = array( 'heading_text' => __('Sportdetails',GEODIRECTORY_TEXTDOMAIN), 'is_active_tab' => false, 'is_display' => apply_filters('geodir_detail_page_tab_is_display', true, 'sportdetails_tab'), 'tab_content' => '' ); return $tab_array ; } add_action('geodir_after_tab_content' ,'geodir_my_new_tab_content'); function geodir_my_new_tab_content($tab_index) { if($tab_index =='sportaktiv_tab') { global $wpdb; $id = get_the_ID(); $sportaktivinfos = $wpdb->get_var("SELECT geodir_c4y_sportaktiv_infos FROM geodir_gd_aktiv_hotels_detail WHERE post_id = $id "); echo $sportaktivinfos; } if($tab_index =='routen_tab') { global $wpdb; $id = get_the_ID(); $routeninfos = $wpdb->get_var("SELECT geodir_c4y_detail_nearby_routes FROM geodir_gd_aktiv_hotels_detail WHERE post_id = $id "); echo $routeninfos; } if($tab_index =='sportdetails_tab') { global $wpdb; $id = get_the_ID(); $bikeinfos = $wpdb->get_var("SELECT geodir_c4y_detail_sport FROM geodir_gd_aktiv_hotels_detail WHERE post_id = $id "); echo $bikeinfos; } }
Thanks for help .
ThomasP.S: and sorry for my bad english 😉 not my native language.
August 1, 2014 at 11:33 am #10622Hello Thomas,
try the following code (not tested on my site)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['sportaktiv_tab'] = array( 'heading_text' => __('SPORTaktiv',GEODIRECTORY_TEXTDOMAIN), 'is_active_tab' => false, 'is_display' => apply_filters('geodir_detail_page_tab_is_display', true, 'sportaktiv_tab'), 'tab_content' => '' ); $tab_array['routen_tab'] = array( 'heading_text' => __('Routen',GEODIRECTORY_TEXTDOMAIN), 'is_active_tab' => false, 'is_display' => apply_filters('geodir_detail_page_tab_is_display', true, 'routen_tab'), 'tab_content' => '' ); $tab_array['sportdetails_tab'] = array( 'heading_text' => __('Sportdetails',GEODIRECTORY_TEXTDOMAIN), 'is_active_tab' => false, 'is_display' => apply_filters('geodir_detail_page_tab_is_display', true, 'sportdetails_tab'), 'tab_content' => '' ); return $tab_array ; } add_action('geodir_after_tab_content' ,'geodir_my_new_tab_content'); function geodir_my_new_tab_content($tab_index) { global $post; $current_posttype = geodir_get_current_posttype(); if($current_posttype != "YOUR CUSTOM TYPE eg gd_place") { if($tab_index =='sportaktiv_tab') { global $wpdb; $id = get_the_ID(); $sportaktivinfos = $wpdb->get_var("SELECT geodir_c4y_sportaktiv_infos FROM geodir_gd_aktiv_hotels_detail WHERE post_id = $id "); echo $sportaktivinfos; } if($tab_index =='routen_tab') { global $wpdb; $id = get_the_ID(); $routeninfos = $wpdb->get_var("SELECT geodir_c4y_detail_nearby_routes FROM geodir_gd_aktiv_hotels_detail WHERE post_id = $id "); echo $routeninfos; } if($tab_index =='sportdetails_tab') { global $wpdb; $id = get_the_ID(); $bikeinfos = $wpdb->get_var("SELECT geodir_c4y_detail_sport FROM geodir_gd_aktiv_hotels_detail WHERE post_id = $id "); echo $bikeinfos; } } }
what I’ve done is to add an if statement so you need to add your post type in the row where it says:
if($current_posttype != “YOUR CUSTOM TYPE eg gd_place”) {Don’t worry about your english, it is surely better than mine 😉
August 1, 2014 at 12:02 pm #10628Hello Simone,
thanks for the quick answer but the code dont work for me.
I get always the Tabs and they are always empty.
August 1, 2014 at 12:03 pm #10629could you please give me your FTP in a private reply? thanks
August 1, 2014 at 12:11 pm #10630This reply has been marked as private.August 1, 2014 at 12:12 pm #10631@Simone sorry to bother but he wants to remove the tab not the content, so here is better code
add_filter('geodir_detail_page_tab_list_extend', 'geodir_detail_page_tab_list_extend') ; function geodir_detail_page_tab_list_extend($tab_array) { global $post ; if($post->post_type != 'Write the post type u want to hide this tab for') // e.g gd_place { $tab_array['sportaktiv_tab'] = array( 'heading_text' => __('SPORTaktiv',GEODIRECTORY_TEXTDOMAIN), 'is_active_tab' => false, 'is_display' => apply_filters('geodir_detail_page_tab_is_display', true, 'sportaktiv_tab'), 'tab_content' => '' ); $tab_array['routen_tab'] = array( 'heading_text' => __('Routen',GEODIRECTORY_TEXTDOMAIN), 'is_active_tab' => false, 'is_display' => apply_filters('geodir_detail_page_tab_is_display', true, 'routen_tab'), 'tab_content' => '' ); $tab_array['sportdetails_tab'] = array( 'heading_text' => __('Sportdetails',GEODIRECTORY_TEXTDOMAIN), 'is_active_tab' => false, 'is_display' => apply_filters('geodir_detail_page_tab_is_display', true, 'sportdetails_tab'), 'tab_content' => '' ); }// end of if for post type check return $tab_array ; }
Let me know if it works.
Thanks
August 1, 2014 at 12:19 pm #10633oops..ive placed the if statement in the wrong functions, it was supposed to stay in the previous “geodir_detail_page_tab_list_extend”.
edit- wow Vikas just wrote that 🙂
August 1, 2014 at 12:41 pm #10634Hello,
thanks to both code from Vikas works perfect.
greets Thomas
-
AuthorPosts
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket