Advertisement:

Author Topic: how to print the current city name the user is viewing  (Read 2963 times)

omid_firoznia

  • Newbie
  • *
  • Posts: 37
Re: how to print the current city name the user is viewing
« Reply #15 on: January 20, 2019, 03:40:04 pm »
Thanks a lot.

I use region as subdomain , what shall I do about them that show name of region ?
I mean for region only showing region name and for city only showing city name? (Right now city name is ok.)

WEBmods

  • Hero Member
  • *****
  • Posts: 937
  • github.com/webmods-croatia/love-osclass/ | patrick
Re: how to print the current city name the user is viewing
« Reply #16 on: January 20, 2019, 03:53:50 pm »
So you want this code: <?php echo ucwords(preg_replace("~^(.*?)\..*$~", "$1", $_SERVER[HTTP_HOST])); ?> to output region name and not slug?

Use this then:

Code: [Select]
<?php echo Region::newInstance()->findBySlug(ucwords(preg_replace("~^(.*?)\..*$~""$1"$_SERVER[HTTP_HOST])))['s_name']; ?>

It will search for the region by its slug and output its name.

Regards.

omid_firoznia

  • Newbie
  • *
  • Posts: 37
Re: how to print the current city name the user is viewing
« Reply #17 on: January 23, 2019, 05:52:15 pm »
thanks a lot.

if i don't use sub-domain how can i combain <?php echo osc_search_city(); ?> and <?php echo osc_search_region(); ?> to show the name , But i want when its in a city just show name of city with out region name.

WEBmods

  • Hero Member
  • *****
  • Posts: 937
  • github.com/webmods-croatia/love-osclass/ | patrick
Re: how to print the current city name the user is viewing
« Reply #18 on: January 25, 2019, 01:41:15 am »
osc_search_region() and osc_search_city() will only work for search.

Use this to show only city when a region is selected or only region when no city is selected.

Code: [Select]
echo (osc_search_city() != '') ? osc_search_city() : osc_search_region();

Regards.

omid_firoznia

  • Newbie
  • *
  • Posts: 37
Re: how to print the current city name the user is viewing
« Reply #19 on: January 30, 2019, 06:28:47 pm »
thanks a lot.    ;)    :)    im very thanks full.   ;)
--------------------------------------------------------------------------------

1-how to set {logo name} link that when in city or region or region name clicking on it its goes to first page of That city or region not HomePage.


2-also how to put this LINK on city name and region name that showing on header.

WEBmods

  • Hero Member
  • *****
  • Posts: 937
  • github.com/webmods-croatia/love-osclass/ | patrick
Re: how to print the current city name the user is viewing
« Reply #20 on: January 30, 2019, 08:32:35 pm »
You need to put an anchor (https://www.w3schools.com/html/html_links.asp) with the href attribute of "echo (osc_search_city() != '') ? osc_search_url(array('sCity' => osc_search_city())) : osc_search_url(array('sRegion' => osc_search_region()));"

Regards.

omid_firoznia

  • Newbie
  • *
  • Posts: 37
Re: how to print the current city name the user is viewing
« Reply #21 on: January 31, 2019, 05:07:52 am »
thanks a lot , in witch file i have to put the code?

omid_firoznia

  • Newbie
  • *
  • Posts: 37
Re: how to print the current city name the user is viewing
« Reply #22 on: January 31, 2019, 05:39:00 am »
maybe change in function.php

---------------------------------------------------------------------------
Code: [Select]
  /* logo */
    if( !function_exists('logo_header') ) {
        function logo_header() {
             $logo = osc_get_preference('logo','bender');
             $html = '<a href="'.osc_base_url().'"><img border="0" alt="' . osc_page_title() . '" src="' . bender_logo_url() . '"></a>';
             if( $logo!='' && file_exists( osc_uploads_path() . $logo ) ) {
                return $html;
             } else {
                return '<a href="'.osc_base_url().'">'.osc_page_title().'</a>';
            }
        }
    }

WEBmods

  • Hero Member
  • *****
  • Posts: 937
  • github.com/webmods-croatia/love-osclass/ | patrick
Re: how to print the current city name the user is viewing
« Reply #23 on: January 31, 2019, 08:51:53 am »
Yes, change osc_base_url() with my code.

Regards.

omid_firoznia

  • Newbie
  • *
  • Posts: 37
Re: how to print the current city name the user is viewing
« Reply #24 on: January 31, 2019, 07:21:35 pm »
I did as you said but doesn't work!
getting this error:

Parse error: syntax error, unexpected '') ? osc_search_url(array('' (T_CONSTANT_ENCAPSED_STRING) in public_html/oc-content/themes/bender/functions.php on line 176

here is the code:

Code: [Select]
    /* logo */
    if( !function_exists('logo_header') ) {
        function logo_header() {
             $logo = osc_get_preference('logo','bender');
             $html = '<a href="echo (osc_search_city() != '') ? osc_search_url(array('sCity' => osc_search_city())) : osc_search_url(array('sRegion' => osc_search_region()));"><img border="0" alt="' . osc_page_title() . '" src="' . bender_logo_url() . '"></a>';
             if( $logo!='' && file_exists( osc_uploads_path() . $logo ) ) {
                return $html;
             } else {
                return '<a href="echo (osc_search_city() != '') ? osc_search_url(array('sCity' => osc_search_city())) : osc_search_url(array('sRegion' => osc_search_region()));">'.osc_page_title().'</a>';
            }
        }
    }
    /* logo */
« Last Edit: January 31, 2019, 07:24:13 pm by omid_firoznia »

WEBmods

  • Hero Member
  • *****
  • Posts: 937
  • github.com/webmods-croatia/love-osclass/ | patrick
Re: how to print the current city name the user is viewing
« Reply #25 on: January 31, 2019, 08:16:16 pm »
Here goes full code that will make logo go to home on all pages but search pages, when on search page it goes to city or region:

Code: [Select]
<?php
    
/* logo */
    
if( !function_exists('logo_header') ) {
        function 
logo_header() {
             
$link osc_base_url();
             if(
osc_is_search_page()) {
                 
$city osc_search_city();
                 
$region osc_search_region_id();
                 if(
$city != '') {
                     
$link osc_search_url(array('sCity' => $city));
                 } elseif(
$region != '') {
                     
$link osc_search_url(array('sRegion' => $region));
                 }
             }
             
$logo osc_get_preference('logo','bender');
             
$html '<a href="'.$link.'"><img border="0" alt="' osc_page_title() . '" src="' bender_logo_url() . '"></a>';
             if( 
$logo!='' && file_existsosc_uploads_path() . $logo ) ) {
                return 
$html;
             } else {
                return 
'<a href="'.$link.'">'.osc_page_title().'</a>';
            }
        }
    }
    
/* logo */

Regards.