Advertisement:

Author Topic: [Solved]How to display the telephone number by two-digit group  (Read 121 times)

grisbi

  • Newbie
  • *
  • Posts: 44
Hello

How to display the telephone number by two-digit group

I made this modification to display the phone number thanks to the code proposed by byGator:

https://forums.osclass.org/themes/add-phone-number-field-for-bender-theme

I would like to display this number in groups of two digits so that it is more readable like for example 01 99 00 00 00
 
how to do ?

merci
« Last Edit: August 01, 2019, 03:42:30 am by grisbi »

WEBmods

  • Hero Member
  • *****
  • Posts: 937
  • github.com/webmods-croatia/love-osclass/ | patrick
Re: How to display the telephone number by two-digit group
« Reply #1 on: July 31, 2019, 02:32:05 pm »
Hello!

Use this piece of code to show the number.

Code: [Select]
$item_phone = osc_item_contact_phone();
if($item_phone != '') {
    $formatted_phone = implode(' ', str_split($item_phone, 2));
    echo '<p>'.__('Phone').': '.$formatted_phone.'</p>';
}

Regards.

grisbi

  • Newbie
  • *
  • Posts: 44
Re: How to display the telephone number by two-digit group
« Reply #2 on: July 31, 2019, 11:09:49 pm »
Hi WEBmods
it works well
but my number is hidden by a button, a tip that I found on the forum.

like this :

Code: [Select]
<?php if ( osc_item_contact_phone() ) { ?>
         <div><button><?php _e('Click to display the number''bender'); ?></button> 
<p style="display: none"> <img src="<?php echo osc_current_web_theme_url('images/tel.png') ; ?>" alt="" title="custom_fields" style="float:left; margin-right:4px; margin-top:0px;">   
 <?php echo osc_item_contact_phone(); ?></p>
        <script>$("button").click(function () {  $("p").show("slow");  $(this).hide();});</script></div>
                  <?php ?>

How to do now ?

see you soon

WEBmods

  • Hero Member
  • *****
  • Posts: 937
  • github.com/webmods-croatia/love-osclass/ | patrick
Re: How to display the telephone number by two-digit group
« Reply #3 on: July 31, 2019, 11:31:33 pm »
Code: [Select]
<?php if(osc_item_contact_phone()) { ?>
    <?php
    $phone 
osc_item_contact_phone(); // Get phone number.
    
$phone str_replace(' '''$phone); // Remove spaces in phone number.
    
$phone implode(' 'str_split($phone2)); // Split phone in two-digit groups.
    
?>

    <div>
        <button class="display-phone"><?php _e('Click to display the number''bender'); ?></button> 
<p style="display: none" class="hidden-phone">
            <img src="<?php echo osc_current_web_theme_url('images/tel.png') ; ?>" style="float:left; margin-right:4px; margin-top:0px;">   
            <?php echo $phone?>
        </p>
        <script>
        $(".display-phone").click(function () {
            $(".hidden-phone").show("slow");
            $(this).hide();
        });
        </script>
    </div>
<?php ?>

Regards.
« Last Edit: July 31, 2019, 11:33:14 pm by WEBmods »

grisbi

  • Newbie
  • *
  • Posts: 44
Re: How to display the telephone number by two-digit group
« Reply #4 on: August 01, 2019, 01:02:33 am »
Thank you Many WEBmods for your help
it works perfectly and especially it allows me to learn the operation of Osclass

PS : How to mark this topic as resolved ?
« Last Edit: August 01, 2019, 01:04:57 am by grisbi »

WEBmods

  • Hero Member
  • *****
  • Posts: 937
  • github.com/webmods-croatia/love-osclass/ | patrick
Re: How to display the telephone number by two-digit group
« Reply #5 on: August 01, 2019, 02:06:59 am »
You're welcome! :)

Edit your first post in the topic and change the title to "[SOLVED] How to display the telephone number by two-digit group".

Regards.