Top Questions

  • 5.11 Years

    • Category : Wordpress
    • Location : Mohali
    • Posted On : Feb 16, 2018

    Try this code in your functions.php file

    add_filter( 'woocommerce_billing_fields', 'woo_filter_state_billing', 10, 1 );
    add_filter( 'woocommerce_shipping_fields', 'woo_filter_state_shipping', 10, 1 );
    function woo_filter_state_billing( $address_fields ) { 
      $address_fields['billing_state']['required'] = false;
    	return $address_fields;
    }
    function woo_filter_state_shipping( $address_fields ) { 
    	$address_fields['shipping_state']['required'] = false;
    	return $address_fields;
    }
     
  • 2.9 Years

    • Category : Wordpress
    • Location : Chandigarh
    • Posted On : Apr 1, 2016

    Upload multiple video file and store its in database using this code.

    <?php
    $server_url="http://".$_SERVER['SERVER_NAME'].dirname($_SERVER["REQUEST_URI"].'?').'/';
    $path = preg_replace('/wp-content.*$/','',__DIR__);
    $path = preg_replace('/wp-content(?!.*wp-content).*/','',__DIR__);
    include($path.'wp-load.php');
    /******Database Connect end*******/
    if(isset($_POST['add']))
    {
    $_FILES["fileToUpload"]["name"];
    if ( ! function_exists( 'wp_handle_upload' ) ) {
    require_once( ABSPATH . 'wp-admin/includes/file.php' ); }
    $upload_overrides = array( 'test_form' => false );
     $files = $_FILES["fileToUpload"]; 
        foreach ($files['name'] as $key => $value) {           
                if ($files['name'][$key]) {
                    $file = array(
                        'name' => $files['name'][$key],
                        'type' => $files['type'][$key],
                        'tmp_name' => $files['tmp_name'][$key],
                        'error' => $files['error'][$key],
                        'size' => $files['size'][$key]
                    );
    
                   $_name = $file['name'];
                   $f_name =  explode('.', $_name);
                    $rand = rand(0000,9999);
                   $addname = $f_name['0'].$rand;
                   $total_name = $addname."." .$f_name['1'];
    
                  $insertname[] = $total_name;
    
    
    
                   $file_s = array( 'name' =>  $total_name,
                        'type' => $files['type'][$key],
                        'tmp_name' => $files['tmp_name'][$key],
                        'error' => $files['error'][$key],
                        'size' => $files['size'][$key]
                    );
    
    
    
    
                 
    
                    
                        $newupload = wp_handle_upload($file_s,$upload_overrides);
                      $patoooooooooh[] = $newupload['url'];
                   
                }
            }
    $nname=implode("&",$patoooooooooh);
    mysql_query("insert table_name (`column_name`) values ('$nname')");
    }
    ?>
    /*****Php Code end and html start*****/
    <form class="form-horizontal" method="post" enctype="multipart/form-data">
    <input type="file" name="fileToUpload[]" id="fileToUpload" class="add_file">
    <div class="demo">
    </div>
    <button name="add" type="submit">Add</button>
    </form>
    /********Html End & jquery Start**************/
    
    <script>
    $(document).ready(function() {
    // $('.add_field_button').keyup(function(e){
      var rand=Math.random();
    $(document).on('change','.add_file',function(e){
      //on add input button click
            e.preventDefault();
                $('.demo').append("<div class='sas'><br/><input type='file' name='fileToUpload[]' class='add_file' ><a href='#' class='remove_field'><i class='fa fa-trash-o'></i></a></div>"); //add input box
        });
      $('.demo').on('click', '.remove_field', function(e) {
        $(this).closest('.sas').remove();
      return false;
    });
    });
    </script>
  • 2.9 Years

    • Category : Php
    • Location : Chandigarh
    • Posted On : Jul 31, 2016

    share on whatsapp using php

    <a data-text="Your message goes here.." data-link="http://dorcode.com" class="btn btn-sucess">Share</a>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
    <script type="text/javascript">
    
    jQuery(document).ready(function() {
    
    var isMobile = {
        Android: function() {
            return navigator.userAgent.match(/Android/i);
        },
        BlackBerry: function() {
            return navigator.userAgent.match(/BlackBerry/i);
        },
        iOS: function() {
            return navigator.userAgent.match(/iPhone|iPad|iPod/i);
        },
        Opera: function() {
            return navigator.userAgent.match(/Opera Mini/i);
        },
        Windows: function() {
            return navigator.userAgent.match(/IEMobile/i);
        },
        any: function() {
            return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
        }
    };
    jQuery(document).on("click", '.whatsapp', function() {
            if( isMobile.any() ) {
    
                var text = jQuery(this).attr("data-text");
                var url = jQuery(this).attr("data-link");
                var message = encodeURIComponent(text)   " - "   encodeURIComponent(url);
                var whatsapp_url = "whatsapp://send?text="   message;
                window.location.href = whatsapp_url;
            } else {
                alert("Please share on mobile device");
            }
    
        });
    });
    </script>
     
  • 5.11 Years

    • Category : Htaccess
    • Location : Mohali
    • Posted On : Dec 15, 2015

    Speed-up your website with these simple .htaccess tricks

    # Do not remove this line or mod_rewrite rules and search engine friendly URLs will stop working
    RewriteBase /
    
    # BEGIN Cache-Control Headers
    <ifModule mod_headers.c>
     <filesMatch ".(ico|jpe?g|png|gif|swf)$">
       Header set Cache-Control "public"
     </filesMatch>
     <filesMatch ".(css)$">
       Header set Cache-Control "public"
     </filesMatch>
     <filesMatch ".(js)$">
       Header set Cache-Control "private"
     </filesMatch>
     <filesMatch ".(x?html?|php)$">
       Header set Cache-Control "private, must-revalidate"
     </filesMatch>
    </ifModule>
    # END Cache-Control Headers
    
    <ifmodule mod_expires.c>
    <Filesmatch "\.(jpg|jpeg|png|gif|js|css|swf|ico|woff|mp3)$">
        ExpiresActive on
        ExpiresDefault A2592000
    </Filesmatch>
    </ifmodule>
    
  • 2.9 Years

    • Category : Jquery
    • Location : Chandigarh
    • Posted On : Jan 22, 2016

    add confirmation alert before your link active

    <script>
    function confirmDelete(delUrl) {
      if (confirm("Are you sure you want to delete")) {
        document.location = delUrl;
      }
    }
    </script>
    
    <a href="javascript:confirmDelete('delete.page?id=1')">Delete</a>
    
    or
    
    <a href="delete.page?id=1" onclick="return confirm('Are you sure you want to delete?')">Delete</a>
    
    or
    use this cdn's in your header
    
    https://cdnjs.cloudflare.com/ajax/libs/bootstrap-sweetalert/1.0.1/sweetalert.css
    https://cdnjs.cloudflare.com/ajax/libs/bootstrap-sweetalert/1.0.1/sweetalert.js
    
    
    <a href="delete.page?id=1" class="confirmation">Delete</a>
    
    jQuery('.confirmation').click(function (e) {
        var href = jQuery(this).attr('href');
    
        swal({
            title: "Are you sure?",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "Yes",
            cancelButtonText: "No",
            closeOnConfirm: true,
            closeOnCancel: true
        },
                function (isConfirm) {
                    if (isConfirm) {
                        window.location.href = href;
                    }
                });
    
        return false;
    });
    

  • 5.11 Years

    • Category : Php
    • Location : Mohali
    • Posted On : Dec 8, 2015

    1 Answers

    View More
  • 5.11 Years

    • Category : Php
    • Location : Mohali
    • Posted On : Aug 11, 2017

    WordPress offers built-in functionality for navigating through posts. Theme developers can use simple default wordpress pagination function or other pagination function for better customize.

    // Create table in mysql
    CREATE TABLE `your_table_name` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `title` varchar(200) NOT NULL,
      `addtime` int(20) NOT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
    
    // Insert table data
    INSERT INTO `your_table_name` (`id`, `title`, `addtime`) VALUES
    (1, 'test', 1299446702);	// addtime is timestamp
    
    
    
    <?php
    // insert this code where your want to add pagination
    // ----------- code start -----------
    
    $table_name =  "your_table_name"; 	// enter your table name
    $item_per_page=5;					// enter number 
    
    $all = $wpdb->get_row( "SELECT count(*) as total FROM {$table_name} WHERE 1=1", ARRAY_A );
    $page_number = (get_query_var('page')) ? get_query_var('page') : 1;
    $offset = ($page_number - 1) * $item_per_page;
    $data = $wpdb->get_results( "SELECT * FROM {$table_name} WHERE 1=1 ORDER BY id DESC LIMIT $offset,$item_per_page", ARRAY_A );
    $cou=$page_number*$item_per_page;
    ?>
    
    <h2>Results <?=$page_number ?>-<?=($cou>$all['total'])?$all['total']:$cou ?> of <?=$all['total'] ?></h2>
    <ul class="pagination">
    	<?php echo pagination($all['total'], $item_per_page, $page_number, site_url()."/your-page-name/?page=%d"); ?>
    </ul>
    
    
    <?php
    foreach ($data as $one) {
    ?>
    		<?=$one['id'] ?> <br />
    		<?=$one['title'] ?>
    <?php
    }
    ?>
    // ----------- code end -----------
    
    
    // add function.php in wordpress----------- code start ----
    
    function pagination($item_count, $limit, $cur_page, $link)
    {
           $page_count = ceil($item_count/$limit);
           $current_range = array(($cur_page-2 < 1 ? 1 : $cur_page-2), ($cur_page 2 > $page_count ? $page_count : $cur_page 2));
    
           // First and Last pages
           $first_page = $cur_page > 3 ? '<a href="'.sprintf($link, '1').'">1</a>'.($cur_page < 5 ? ', ' : ' ... ') : null;
           $last_page = $cur_page < $page_count-2 ? ($cur_page > $page_count-4 ? ', ' : ' ... ').'<a href="'.sprintf($link, $page_count).'">'.$page_count.'</a>' : null;
    
           // Previous and next page
           $previous_page = $cur_page > 1 ? '<a href="'.sprintf($link, ($cur_page-1)).'">&lt;&lt;</a>  ' : null;
           $next_page = $cur_page < $page_count ? '  <a href="'.sprintf($link, ($cur_page 1)).'">&gt;&gt;</a>' : null;
    
           // Display pages that are in range
           for ($x=$current_range[0];$x <= $current_range[1];   $x)
                   $pages[] = '<a href="'.sprintf($link, $x).'">'.($x == $cur_page ? '<strong>'.$x.'</strong>' : $x).'</a>';
    
           if ($page_count > 1)
                   return '<p class="pagination">'.$previous_page.$first_page.implode('&nbsp;&nbsp;', $pages).$last_page.$next_page.'</p>';
    }
    
    // add function.php in wordpress----------- code end ----
  • 2.9 Years

    • Category : Php
    • Location : Chandigarh
    • Posted On : Jan 4, 2017

    Easy Multiple Image Using Codeigniter.

    if($_FILES['filename']['name']!='')
     {
           $image=array();
           $counts = count($_FILES['filename']['name']);
           $config['upload_path'] = APPPATH.'uploads/'; //create upload folder in application
                                                        // Give permission -R 777 to upload folder 
           $config['allowed_types'] = '*';
           $files = $_FILES;
           for($i=0; $i<$counts; $i  )
            {       
               if($_FILES['filename']['name'][$i]!='')
     { 
           $_FILES['filename']['name']= time().$files['filename']['name'][$i];
           $_FILES['filename']['type']= $files['filename']['type'][$i];
           $_FILES['filename']['tmp_name']= $files['filename']['tmp_name'][$i];
           $_FILES['filename']['error']= $files['filename']['error'][$i];
           $_FILES['filename']['size']= $files['filename']['size'][$i];
           $this->load->library('upload', $config);
           $this->upload->initialize($config);
           $upload= $this->upload->do_upload('familypicture');
           if($upload){
          $uu=$this->upload->data();
                $image[] =$uu['file_name'];
       }
             }
             }
       $fileToUpload = implode('|',$image);
    }
     
  • 5.11 Years

    • Category : Php
    • Location : Mohali
    • Posted On : Dec 7, 2015
  • 5.11 Years

    • Category : Php
    • Location : Mohali
    • Posted On : Jul 31, 2016

    In order to generate token for access to api and other

    Here is the correct solution:
    $token = bin2hex(openssl_random_pseudo_bytes(16));