Top Questions

  • 2.9 Years

    • Category : Php
    • Location : Chandigarh
    • Posted On : Jun 5, 2016

    Display limited o of word from a string using this code

    echo mb_strimwidth('It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using Content here, content here, making it look like readable English', 0, 50, "...");
     
  • 2.9 Years

    • Category : Php
    • Location : Chandigarh
    • Posted On : Jun 2, 2016

    Get last week start and end date in php

    $previous_week = strtotime("-1 week  1 day");
    
    $start_week = strtotime("last sunday midnight",$previous_week);
    $end_week = strtotime("next saturday",$start_week);
    
    $start_week = date("Y-m-d",$start_week);
    $end_week = date("Y-m-d",$end_week);
    
    echo $start_week.' '.$end_week ;
     
  • 5.11 Years

    • Category : Wordpress
    • Location : Chandigarh, India
    • Posted On : May 27, 2016

    I am fairly new to woocommerce and although the other day the add to cart and cart page was displaying fine. I am now finding that going to my cart page brings up a blank page.

    add this code in function.php
    add_filter('woocommerce_add_to_cart', 'custome_add_to_cart');
    function custome_add_to_cart() {
        global $woocommerce;
     $woocommerce->session->set_customer_session_cookie(true);
    }
     
  • 5.11 Years

    • Category : Wordpress
    • Location : Chandigarh, India
    • Posted On : Apr 28, 2016

    woo-commerce cart item session start and destroy after 30 Min

    <?php
    
    global $woocommerce;
    if (!isset($_SESSION['EXPIRES']) || $_SESSION['EXPIRES'] < time()) {
     $woocommerce->cart->empty_cart(); 
    } else {
      $_SESSION['EXPIRES'] = time() 1800;
    }
    
  • 2.9 Years

    • Category : Ajax
    • Location : Chandigarh
    • Posted On : Apr 25, 2016

    print your custom data or field using ajax

    function printinvoice(id){
         $.ajax({
           url: "sample.php",            
                type: "POST",
           data: "print_id=" id,
          success: function(data) {
         newWin= window.open();
                            newWin.document.write(data);
                            newWin.document.close();
                            newWin.focus();
                            newWin.print();
                             newWin.close();
          },
      error: function() {
         
          }
       }); 
    }
  • 5.11 Years

    • Category : Php
    • Location : Chandigarh, India
    • Posted On : Apr 18, 2016

    When i click the first upload field (uploading process are success) after insert into post that corresponding media url is appear in the second field not in first. I am not sure where is the problem any suggestion would be great.

    <?php
    wp_enqueue_script('jquery');
    // This will enqueue the Media Uploader script
    wp_enqueue_media();
    ?>
        <div>
        <label for="image_url">Image</label>
        <input type="text" name="image_url" id="image_url" class="regular-text">
        <input type="button" name="upload-btn" id="upload-btn" class="button-secondary" value="Upload Image">
     </div>
    <script type="text/javascript">
    
    jQuery(document).ready(function($){
        $('#upload-btn').click(function(e) {
            e.preventDefault();
            var image = wp.media({ 
                title: 'Upload Image',
                // mutiple: true if you want to upload multiple files at once
                multiple: false
            }).open()
            .on('select', function(e){
                // This will return the selected image from the Media Uploader, the result is an object
                var uploaded_image = image.state().get('selection').first();
                // We convert uploaded_image to a JSON object to make accessing it easier
                // Output to the console uploaded_image
                console.log(uploaded_image);
                var image_url = uploaded_image.toJSON().url;
                // Let's assign the url value to the input field
                $('#image_url').val(image_url);
            });
        });
    });
    </script>
    
    
    
    // UPLOAD ENGINE
    function load_wp_media_files() {
        wp_enqueue_media();
    }
    add_action( 'admin_enqueue_scripts', 'load_wp_media_files' );
     
  • 2.9 Years

    • Category : Mysql
    • Location : Chandigarh
    • Posted On : Apr 15, 2016

    Foreign Key integration between two tables

    $id='15';
    mysql_query("select table1.column1,table1.column2,table1.column3, table1.column4, table2.column1, table2.column2, table2.column3, from table1name table1, table2name table2 where table2.column1=table2.column1 and table1.column1='$id'");
     
  • 2.9 Years

    • Category : Mysql
    • Location : Chandigarh
    • Posted On : Mar 31, 2016

    This code resolve special character problem during fetch data from database.just copy and paste code where you create your connection.

    //copy in config file
    mysql_set_charset('utf8');
     
  • 2.9 Years

    • Category : Php
    • Location : Chandigarh
    • Posted On : Mar 30, 2016

    You can generate refer code or random code using this code in php.its easy to implement and use.

    <?php
        $character_set_array = array();
        $character_set_array[] = array('count' => 6, 'characters' => 'abcdefghijklmnopqrstuvwxyz');
        $character_set_array[] = array('count' => 1, 'characters' => '0123456789');
        $character_set_array[] = array('count' => 1, 'characters' => '!@#$ -*&?:');
        $temp_array = array();
        foreach ($character_set_array as $character_set) {
            for ($i = 0; $i < $character_set['count']; $i   ) {
                $temp_array[] = $character_set['characters'][rand(0, strlen($character_set['characters']) - 1)];
            }
        }
        shuffle($temp_array);
        $refercode= implode('', $temp_array);
        echo $refercode;
        ?>
  • 0.0 Years

    • Category : Wordpress
    • Location : Unknown
    • Posted On : Mar 22, 2016

    Get Posts By Sub Category ID in Wordpress.

    <?php query_posts('cat=10&showposts=-1');
               $posts = get_posts('category=10&numberposts=3&offset=0');
                foreach ($posts as $post) : start_wp(); ?>
    
                <?php $cats = get_the_category($post->ID);
                $subcategories = array();
                foreach( $cats as $cat ) {
                $subcats = get_categories('child_of='.$cat->term_id);
                if($subcats) {
                foreach( $subcats as $subcat )
                {  $subcategories[] = sanitize_title($subcat->name); }
                }
                }
                $subcats = array_unique($subcategories);
                if($subcats) {
                $subcats = implode(' ',$subcats);
                $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID, 'thumbnail') );
               // echo '<li class="' . $subcats . '">';
    
                }
                ?>
                    <figure class="mix portfolio-item print">
                        <img class="img-responsive" src="<?php echo $url; ?>" alt="Portfolio Item">
                        <a href="<?php echo $url; ?>" title="Title Four" rel="portfolio" class="fancybox"><span class="plus"></span></a>
                        <figcaption class="mask">
                            <h3><?php the_title(); ?></h3>
                            <span><?php the_content(); ?></span>
                        </figcaption>
                    </figure>
    
    <?php endforeach ?>