change location

This topic contains 26 replies, has 3 voices, and was last updated by  Strong Coffee 9 years, 9 months ago.

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

Open Support Ticket

Tagged: 

  • Author
    Posts
  • #30477

    Strong Coffee
    Full Member
    Post count: 124

    On your demo site you have an option to Change Location in your header that lets you select the country/region/city. How do you add that? Can it be added to the sidebar?

    #30479

    Simone
    Expired Member
    Post count: 3515

    Hello, to enable the location switcher, first create a menu in Appearance/menu, then link it to GD going to Geodirectory/Design and in the navigation tab select your menu, and then go to the MultiLocation settings and rich the option where it says “Show location switcher in menu”

    to add it in your sidebar, or wherever you want, you can insert this shortcode

    
    
    [geodir_location_tab_switcher autoredirect="1"]
    

    in a text widget

    #30571

    Strong Coffee
    Full Member
    Post count: 124

    Is there a way to just show the city using the shortcode?

    #30577

    Simone
    Expired Member
    Post count: 3515

    I believe you can use this in your template

    
    
    $current_location = geodir_get_current_location();
    echo $current_location ;

    and it will show only the city, but this needs to be inserted inside a function or in the child theme

    #30579

    Paolo
    Site Admin
    Post count: 31206

    or create a shortcode and use it anywhere by adding this in your active theme functions.php

    
    
    
    // Add Shortcode
    function gd_curr_loc_shortcode() {
    
    	// get the location
    	$current_location = geodir_get_current_location();
    	// return the location
    return $current_location ;
    
    }
    add_shortcode( 'gd_curr_location', 'gd_currlocation_shortcode' );

    than use shortcode [gd_curr_location].

    Haven’t tested so use with care…

    Thx

    #30596

    Strong Coffee
    Full Member
    Post count: 124

    Added the code to my child theme’s function.php file then added the shortcode to my sidebar widget and it just displays “[gd_curr_location]” in the sidebar.

    #30597

    Strong Coffee
    Full Member
    Post count: 124
    This reply has been marked as private.
    #30602

    Paolo
    Site Admin
    Post count: 31206

    you need to make your widgets shortcode ready. In wordpress shortcode are ment to be used in content area of posts and pages.

    Add this to your functions.php

    add_filter('widget_text', 'do_shortcode');

    Thx

    #30620

    Strong Coffee
    Full Member
    Post count: 124

    Still get the shortcode displaying as text on the page. Here’s what I added to my functions.php file:

    add_filter(‘widget_text’, ‘do_shortcode’);

    // Apply filter
    add_filter(‘body_class’, ‘gd_body_classes’);

    function gd_body_classes($classes) {
    if (geodir_is_geodir_page()) { $classes[] = ‘this_is_a_gd_page’;
    return $classes;}
    }

    // Add Shortcode
    function gd_curr_loc_shortcode() {

    // get the location
    $current_location = geodir_get_current_location();
    // return the location
    return $current_location ;

    }
    add_shortcode( ‘gd_curr_location’, ‘gd_currlocation_shortcode’ );

    #30623

    Paolo
    Site Admin
    Post count: 31206

    There was an error in the code provided and actually there was a much easier way to do it:

    add_shortcode( 'gd_curr_location', 'geodir_get_current_location' );

    Than use [gd_curr_location] to call the shortcode.

    However this will only show the location once a location has been set and without the Location Switcher you will never be able to set one…

    Once you add the location switcher allowing users to set a location, that text widget will show the location name…

    Thx

    #30699

    Strong Coffee
    Full Member
    Post count: 124

    Sorry – I’m confused. So basically their isn’t a way to just show the city?

    #30701

    Paolo
    Site Admin
    Post count: 31206

    Not until you set one with the location switcher.

    #30726

    Strong Coffee
    Full Member
    Post count: 124

    i’ve added both the shortcodes to my sidebar [geodir_location_tab_switcher autoredirect=”1″] and [gd_curr_location] but i only see the location switcher with country/region/city even after i select a location from the location switcher.

    #30802

    Paolo
    Site Admin
    Post count: 31206

    Hi,

    I just tested this here: wpgeo.directory/

    and after you select a location via location switcher, the location name appears at the bottom of the sidebar, but because that function is echoing the output and shortcodes best practice would require to return the output, it is breaking the widget html appearing before the title.

    I’ll ask Stiofan if he can think of anything.

    Thx

    #30822

    Paolo
    Site Admin
    Post count: 31206

    Ok,

    obviously our wizard had the solution:

    
    
    
     // Add Shortcode for current location name
    function geodir_current_loc_shortcode() {
     ob_start();
     geodir_get_current_location();
     $output = ob_get_contents();
     ob_end_clean();
     return $output;
    }
    add_shortcode( 'gd_current_location_name', 'geodir_current_loc_shortcode' );

    This is being added to next core release, so before updating next time, make sure to remove the code from your child theme or it will throw an error.

    Thanks

Viewing 15 posts - 1 through 15 (of 27 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