mohit
Mohit@mohit

  • 2 years-11 months

    How to change format of Phone number in input text as you type?

    • Category : php
    • Location : Chandigarh, India
    • Posted On : May 03, 2018
    • Posted by : Mohit

    I'm currently displaying phone numbers like 18003336523. However, I need the number to be formatted in a more human-readable form, for example: 1-800-333-6523.

    <script>
    
    jQuery('.wpcf7-tel').keydown(function (e) {
      var key = e.charCode || e.keyCode || 0;
      $phone = jQuery(this);
    
      // Auto-format- do not expose the mask as the user begins to type
      if (key !== 8 && key !== 9) {
          
    console.log($phone.val().length);
       if ($phone.val().length === 1) {
        $phone.val($phone.val() + '-');
       }
       if ($phone.val().length === 5) {
        $phone.val($phone.val() + '-');
       }   
       if ($phone.val().length === 9) {
        $phone.val($phone.val() + '-');
       }
       if ($phone.val().length === 15) {
        return false;
       }
      }
    
      // Allow numeric (and tab, backspace, delete) keys only
      return (key == 8 || 
        key == 9 ||
        key == 46 ||
        (key >= 48 && key <= 57) ||
        (key >= 96 && key <= 105)); 
     })
     
     .bind('focus click', function () {
      $phone = jQuery(this);
      
      if ($phone.val().length === 0) {
       //$phone.val('(');
      }
      else {
       var val = $phone.val();
       $phone.val('').val(val); // Ensure cursor remains at the end
      }
     })
     
     .blur(function () {
      $phone = jQuery(this);
      
      if ($phone.val() === '(') {
       $phone.val('');
      }
     });
    </script>
     
  • 2 years-11 months

    How to include simple pagination in a Wordpress Custom Post Type Query

    • Category : wordpress
    • Location : Chandigarh, India
    • Posted On : Apr 05, 2018
    • Posted by : Mohit

    For a WordPress blog, pagination alludes to showing a predetermined number of posts per page. Pagination permits clients the capacity to explore substantially less demanding and more profound into the chronicles. In this post, I will demonstrate that my past instructional exercise about including Pagination without a module in WordPress, can likewise be utilized on Custom Post Types with no alterations. I will likewise demonstrate the means I took to test my past instructional exercise's pagination code and demonstrate that it is as yet substantial for custom post writes.

    <?php
    $paged = (get_query_var('page')) ? get_query_var('page') : 1;          
    $args = array( 'paged'=> $paged,'post_type' => 'product','orderby' => 'post_date','order'=> 'ASC','posts_per_page' => 10,'post_status'=>'publish');        
    
    $query = new WP_Query($args);
    if ($query->have_posts()) : 
    while ($query->have_posts()) : $query->the_post();
        $id=get_the_ID();
    ?> 
          
    <a href="<?php the_permalink() ?>" class="post-title">
        <h2><?php the_title();?></h2>
    </a>
    <div class="post-content"> <?php echo '<p>'.substr(get_the_content(),0,190).'...</p>'; ?> </div>
    
    <?php
    endwhile; endif;
    ?>
     <?php
     echo '<div class="blogPager">';
     echo '<ul class="pagination"> ';
     if( $paged-1 >= 1){
        echo ' <li class="'.($i == $paged ? 'active ' : '').'page button"><a   href="'.get_pagenum_link(($paged-1 > 0 ? $paged-1 : 1)).'"  > Previous</a></li>';
     }
    
    if($query->max_num_pages > 10) {
        for($i=1;$i<=$query->max_num_pages;$i++){
            echo '<li class="'.($i == $paged ? 'active ' : '').'page button"><a  href="'.
           get_pagenum_link($i).'">'.$i.'</a></li>';
    
        }
    }
    if( $query->max_num_pages > $paged  ) {
        echo '<li class="'.($i == $paged ? 'active ' : '').'page button"> <a   href="'.get_pagenum_link(($paged+1 <= $query->max_num_pages ? $paged+1 :
                $query->max_num_pages)).'">Next </a></li>';
    }
    echo '</ul> ';
    echo '</div> ';
    wp_reset_postdata();
    ?>
     
No items found