Top Questions:

  • 3 years-4 months

    Create Menu/Submenu

    • Category : wordpress
    • Location : Chandigarh
    • Posted On :
    • Posted by : Guley

    Create custom menu and sub-menu in worpress

    add_action('admin_menu', 'main_menu');
    function main_menu()
    {
       add_menu_page( 'Setting' , 'Setting' , 'manage_options' , __FILE__ , 'setting');
       add_submenu_page( __FILE__ , 'Submenu1', 'Submenu1' , 'manage_options' , __FILE__ . 'Submenu1' , 'Submenu1');
    }
    
    /* Menu*/
    
    function Submenu1(){
    	echo "Submenu1 Page";
    }
    
    /* Sub Menu*/
    
    function setting(){
    	echo "Setting Page";
    }
     
  • 5 years-11 months

    Wordpress not working get_template_directory_uri with a child theme

    • Category : wordpress
    • Location : Chandigarh, India
    • Posted On :
    • Posted by : Vikas

    How to get WordPress Child Theme Path.

    When you create a website in wordpress, for this and take a theme and create a child theme.
    Ex. Parent Theme: dorcode
    Child Theme: dorcode-child

    So copy in the folder of the child a style.css and header.php, because you want to modify the header too. you modify the file of the child.

    In my style.css you add the line Template: with the name of the father theme


    // add this function to function.php and replace with get_template_directory_uri() to get_template_directory_child().
    function get_template_directory_child() {
        $directory_template = get_template_directory_uri(); 
        $directory_child = $directory_template.'-child';
        return $directory_child;
    }
     
  • 3 years-4 months

    Prevent requried on ipad and iphone on modal

    • Category : jquery
    • Location : Chandigarh
    • Posted On :
    • Posted by : Guley

    using this code you can prevent required values in html5

    <script src="https://cdnjs.cloudflare.com/ajax/libs/webshim/1.16.0/dev/polyfiller.js" type="text/javascript"></script>
    
    <script> 
            webshim.activeLang('en');
            webshims.polyfill('forms');
            webshims.cfg.no$Switch = true;
    </script>
     
  • 3 years-4 months

    Match date from two columns in mysql

    • Category : mysql
    • Location : Chandigarh
    • Posted On :
    • Posted by : Guley

    You can match two column value using this code

     SELECT * FROM booking WHERE id='1' AND (STR_TO_DATE(`from`, '%d-%m-%Y') <='2017-02-24' AND (STR_TO_DATE(`till`, '%d-%m-%Y') >='2017-02-24')) AND service='test' AND status='0'
  • 3 years-4 months

    JQuery Ajax form using boostrap validation

    • Category : jquery
    • Location : Chandigarh
    • Posted On :
    • Posted by : Guley

    JQuery Ajax form using boostrap validation

     $(document).on('submit','#formid',function(){
     $(this).formValidation({
                                framework: 'bootstrap',
                                fields: {
                                    name: {
                                        validators: {
                                            notEmpty: {
                                                message: 'The name is required'
                                            }
                                        }
                                    },
                                    email: {
                                        validators: {
                                            notEmpty: {
                                                message: 'The email is required'
                                            }
                                        }
                                    },
                                    password: {
                                        validators: {
                                            notEmpty: {
                                                message: 'The password is required'
                                            }
                                        }
                                    },
                                }
                            })
                            .on('success.form.fv', function(e) {
                                e.preventDefault();
                               var Formdata=$(this).serialize();
                                $.ajax({
                                    type: "POST",
                                    url: '', //add page url here
                                    data: Formdata, //send data from here,
                                    success: function(data) {
                                        alert(data);
                                    }
                                });
                            });
                     });
     
  • 5 years-11 months

    How to get all wordpress categories sort by top post categories first

    • Category : wordpress
    • Location : Chandigarh, India
    • Posted On :
    • Posted by : Vikas

    I have below code here. It's display that I want categories names with all details as well. This code to display top post categories first show.

    <?php
    $GLOBALS['uname'] = get_categories();
    define(_SYSTEM_, 'uname');
    class get_all_category_by_top_post {
        public function show() {
            $categories = $this->{_SYSTEM_};
            usort($categories,array($this,'sortByOrder'));
            return $categories;
        }
      public function sortByOrder($a, $b) {
         return $a->count < $b->count;
      }
        public function __get($d) {
            return $GLOBALS[$d];  
        }
    }
    $categories = new get_all_category_by_top_post();
    echo "<pre>";
    print_r($categories->show());
    ?>
  • 3 years-4 months

    Prevent auto rotation while uploading in php

    • Category : php
    • Location : Chandigarh
    • Posted On :
    • Posted by : Guley

    You can prevent auto image rotation problem using this code

    function correctImageOrientation($filename) {
      if (function_exists('exif_read_data')) {
        $exif = exif_read_data($filename);
        if($exif && isset($exif['Orientation'])) {
          $orientation = $exif['Orientation'];
          if($orientation != 1){
            $img = imagecreatefromjpeg($filename);
            $deg = 0;
            switch ($orientation) {
              case 3:
                $deg = 180;
                break;
              case 6:
                $deg = 270;
                break;
              case 8:
                $deg = 90;
                break;
            }
            if ($deg) {
              $img = imagerotate($img, $deg, 0);        
            }
            // then rewrite the rotated image back to the disk as $filename 
            imagejpeg($img, $filename, 95);
          } // if there is some rotation necessary
        } // if have the exif orientation info
      } // if function exists      
    }
    
    $target_dir = "blog/";
    $target_file = $target_dir . basename($blogimg);
    $imge=correctImageOrientation($target_file);
    move_uploaded_file($_FILES["blogimg"]["tmp_name"], $imge); 
    $query=mysql_query("insert into tablename (`image_name`) values ('$target_file')");
    
  • 5 years-11 months

    Get content between two strings, tag and brackets using php

    • Category : php
    • Location : Chandigarh, India
    • Posted On :
    • Posted by : Vikas

    If the strings are different [iframe] and [/iframe], take a look at this. copy his code below:

    <?php
    function get_string_between($string, $start, $end){
        $string = ' ' . $string;
        $ini = strpos($string, $start);
        if ($ini == 0) return '';
        $ini  = strlen($start);
        $len = strpos($string, $end, $ini) - $ini;
        return substr($string, $ini, $len);
    }
    $string='testing [iframe]dorcode.com[/iframe] test';
    $parsed = get_string_between($string, '[iframe]', '[/iframe]');
    echo $parsed; // output: dorcode.com
  • 3 years-4 months

    Multiple Image Upload Using Codeigniter

    • Category : php
    • Location : Chandigarh
    • Posted On :
    • Posted by : Guley

    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 years-11 months

    How do I sorting MySQL result by ages from the birthday date

    • Category : php
    • Location : Chandigarh, India
    • Posted On :
    • Posted by : Vikas

    MySQL sorting by age if your birthday like this 1974-05-15, 1974-05-28 (YEAR,MONTH,DATE)

    <?php
    $table_name="YOUR_TABLE_NAME";
    $column_name="birthdate";
    $age_from=15;
    $age_to=45;
    
    $con=mysqli_connect("localhost","my_user","my_password","my_db");
    // Check connection
    if (mysqli_connect_errno())
      {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
      }
    
    // Perform queries
    
    $sql="SELECT * FROM $table_name WHERE TIMESTAMPDIFF(YEAR, $column_name, CURDATE()) BETWEEN $age_from AND $age_to";
    $result=mysqli_query($con,$sql);
    
    
    // Associative array
    $row=mysqli_fetch_array($result,MYSQLI_ASSOC);
    printf ("%s (%s)\n",$row["id"],$row["name"]);
    
    // Free result set
    mysqli_free_result($result);
    
    mysqli_close($con);
    ?>