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, 5 months ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
  • Author
    Posts
  • #168085

    EH
    Expired Member
    Post count: 96

    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;
                }
            }
    #168241

    EH
    Expired Member
    Post count: 96

    I 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;
                }
            }
    #168273

    EH
    Expired Member
    Post count: 96

    Sorry I have another question. Is there a filter I can apply to only show the new tab if there is content?

    #168296

    Paolo
    Site Admin
    Post count: 31206

    Hi,

    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

    #168736

    EH
    Expired Member
    Post count: 96

    Hi 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.dpuf

    #168860

    Paolo
    Site Admin
    Post count: 31206

    Those 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

    #168876

    EH
    Expired Member
    Post count: 96

    Well, 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.

    #168877

    Paolo
    Site Admin
    Post count: 31206

    Wasn’t that what you wanted?

    Is there a filter I can apply to only show the new tab if there is content?

    Thanks

    #168878

    EH
    Expired Member
    Post count: 96

    Yes, 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.

    #168910

    Paolo
    Site Admin
    Post count: 31206

    You 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

    #168912

    EH
    Expired Member
    Post count: 96

    AHH of course! That worked. Thanks again for the help.

    #168913

    Paolo
    Site Admin
    Post count: 31206

    You are welcome 🙂

Viewing 12 posts - 1 through 12 (of 12 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
20% Discount Offer
Hurry! Get your 20% discount before it expires. Get 20% Discount