Add a new Tab in the listing detail page
This topic contains 11 replies, has 2 voices, and was last updated by Paolo 8 years, 10 months ago.
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket-
AuthorPosts
-
April 21, 2016 at 3:56 pm #168085
I am following along with this blog post https://wpgeodirectory.com/add-a-new-tab-in-the-listing-detail-page and I’m trying to add a new tab with content from a custom field. I think I’m pretty close but my content isn’t showing up. Does anyone see any glaring errors I may have missed?
//Add New tab to GeoDirectory Listing page 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['testimonials_tab'] = array( 'heading_text' => __('Testimonials',GEODIRECTORY_TEXTDOMAIN), 'is_active_tab' => false, 'is_display' => apply_filters('geodir_detail_page_tab_is_display', true,'testimonials_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 =='testimonials_tab'){ global $wpdb; $id = get_the_ID(); $the_testimonials = $wpdb->get_var("SELECT geodir_testimonials FROM geodir_gd_place_detail WHERE post_id = $id "); echo $the_testimonials; } }
April 21, 2016 at 6:57 pm #168241I figured it out I forgot that I included the wp prefix when I set up this site. Here is what worked for me, hopefully it can be of help to someone else too.
//Add New tab to GeoDirectory Listing page 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['testimonials_tab'] = array( 'heading_text' => __('Testimonials',GEODIRECTORY_TEXTDOMAIN), 'is_active_tab' => false, 'is_display' => apply_filters('geodir_detail_page_tab_is_display', true,'testimonials_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 =='testimonials_tab'){ global $wpdb; $id = get_the_ID(); echo $id; $CustomerTestimonials = $wpdb->get_var("SELECT geodir_testimonials FROM wp_geodir_gd_place_detail WHERE post_id = $id "); echo $CustomerTestimonials; } }
April 21, 2016 at 8:35 pm #168273Sorry I have another question. Is there a filter I can apply to only show the new tab if there is content?
April 21, 2016 at 9:31 pm #168296Hi,
in the function to add a new tab, you should check if there are any testimonials and with a conditional tag show it or not.
Let us know if this helps.
Thanks
April 22, 2016 at 12:42 pm #168736Hi Paolo,
I tried this, it seems to work when there is something in that field but when there is not I get the errors listed below.
//Add New tab to GeoDirectory Listing page add_filter('geodir_detail_page_tab_list_extend', 'geodir_detail_page_tab_list_extend'); function geodir_detail_page_tab_list_extend($tab_array) { global $wpdb; $id = get_the_ID(); $CustomerTestimonials = $wpdb->get_var("SELECT geodir_testimonials FROM wp_geodir_gd_place_detail WHERE post_id = $id "); if ($CustomerTestimonials !=''){ $tab_array['testimonials_tab'] = array( 'heading_text' => __('Testimonials',GEODIRECTORY_TEXTDOMAIN), 'is_active_tab' => false, 'is_display' => apply_filters('geodir_detail_page_tab_is_display', true,'testimonials_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 =='testimonials_tab'){ global $wpdb; $id = get_the_ID(); $CustomerTestimonials = $wpdb->get_var("SELECT geodir_testimonials FROM wp_geodir_gd_place_detail WHERE post_id = $id "); echo $CustomerTestimonials; } }
Warning: array_key_exists() expects parameter 2 to be array, null given in C:WampDeveloperWebsiteslocalhostwebrootehpublic_htmlwp-contentpluginsgeodirectorygeodirectory-functionscustom_functions.php on line 1334
Warning: Invalid argument supplied for foreach() in C:WampDeveloperWebsiteslocalhostwebrootehpublic_htmlwp-contentpluginsgeodirectorygeodirectory-functionscustom_functions.php on line 1473
Warning: Invalid argument supplied for foreach() in C:WampDeveloperWebsiteslocalhostwebrootehpublic_htmlwp-contentpluginsgeodirectorygeodirectory-functionscustom_functions.php on line 1511
Warning: Invalid argument supplied for foreach() in C:WampDeveloperWebsiteslocalhostwebrootehpublic_htmlwp-contentpluginsgeodirectorygeodirectory-functionscustom_functions.php on line 1632
– See more at: http://localhost/eh/public_html/places/united-states/massachusetts/boston/audio-1/testing/#sthash.V1wRXY6y.dpufApril 22, 2016 at 3:02 pm #168860Those are just warnings.
I would supress them and log them only in error.log
https://wpgeodirectory.com/docs/faqs/help-i-get-a-php-warning-on-my-pages/
Let us know,
Thx
April 22, 2016 at 4:07 pm #168876Well, suppressing the warnings gets rid of the warning but now no tabs appear on a profile that doesn’t have a testimonial.
This is a “nice to have feature” so for now I’m just going to add testimonials to the main tab since I can do that pretty easily.
April 22, 2016 at 4:12 pm #168877Wasn’t that what you wanted?
Is there a filter I can apply to only show the new tab if there is content?
Thanks
April 22, 2016 at 4:14 pm #168878Yes, it is. However NO tabs are showing now if there isn’t content for testimonials. I was looking for a filter to remove just that tab if there was no content, not all of them.
April 22, 2016 at 4:20 pm #168910You need to add an else statement after this:
if ($CustomerTestimonials !=''){ $tab_array['testimonials_tab'] = array( 'heading_text' => __('Testimonials',GEODIRECTORY_TEXTDOMAIN), 'is_active_tab' => false, 'is_display' => apply_filters('geodir_detail_page_tab_is_display', true,'testimonials_tab'), 'tab_content' => ''); return $tab_array; }
Something like
else {return $tab_array;}
Let us know if this helped.
Thanks
April 22, 2016 at 4:25 pm #168912AHH of course! That worked. Thanks again for the help.
April 22, 2016 at 4:30 pm #168913You are welcome 🙂
-
AuthorPosts
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket