Tuesday, November 18, 2014

How to detect the width of a web browser using jQuery?

Detecting the width of a browser window can be very useful when designing a website, it allows you to create a more responsive design which is suited to the current browser dimensions.
Using the small chunk of jQuery below, you can easily detect the current width of a web browser & perform various actions when the width reaches a particular range of values. When redeveloping my site I opted to use this method to add a different body class to the site when the browser width reaches a below particular points: "smaller" when the width reaches below 960px but greater than 400px and "smallest" when the width is below "400px". The additional body classes then allowed me to alter the position/style of particular elements on the page.


(function($){
  //detect the width on page load
  $(document).ready(function(){
    var current_width = $(window).width();
     //do something with the width value here!
    if(current_width < 400){
      jQuery('body').addClass("probably-mobile");
    }
  });

  //update the width value when the browser is resized (useful for devices which switch from portrait to landscape)
  $(window).resize(function(){
    var current_width = $(window).width();
   //do something with the width value here!
    if(current_width < 400){
      jQuery('body').addClass("probably-mobile");
    }
  });

})(jQuery); 

Tuesday, November 11, 2014

How to install Laravel 4 on wamp server?

First thing which you need to check before starting the setup:

Check whether you have the latest version of the php(5.5)

After that you need to download the setup from the link below:

https://getcomposer.org/

Run the setup and install the composer which will download the Laravel 4 files on your server.

After the completion of the setup -> open cmd(Command Promt).

write composer and press enter.

then change the directory to your server directory.

like in my case it was:

c:\user\home> cd c:\wamp\www

this is the comand to be written in cmd.

then your cmd directory would be like this:

c:\wamp\www>

now write the command for installing the Laravel 4.

which is:

composer create-project laravel\laravel yourfoldername --prefer-dist

in cmd it will be as

c:\wamp\www>composer create-project laravel/laravel yourfoldername --prefer-dist

by writing this command an directory with name yourfoldername will be creater in wamp/www.

Thursday, October 30, 2014

How to create an databse in wordpress plugin?

register_activation_hook( __FILE__, 'jal_install' );
register_activation_hook( __FILE__, 'jal_install_data' );


function jal_install() {
    global $wpdb;
    global $jal_db_version;

    $table_name = $wpdb->prefix . 'liveshoutbox';
   
    /*
     * We'll set the default character set and collation for this table.
     * If we don't do this, some characters could end up being converted
     * to just ?'s when saved in our table.
     */
    $charset_collate = '';

    if ( ! empty( $wpdb->charset ) ) {
      $charset_collate = "DEFAULT CHARACTER SET {$wpdb->charset}";
    }

    if ( ! empty( $wpdb->collate ) ) {
      $charset_collate .= " COLLATE {$wpdb->collate}";
    }

    $sql = "CREATE TABLE name (
        id mediumint(9) NOT NULL AUTO_INCREMENT,
        time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
        name tinytext NOT NULL,
        text text NOT NULL,
        url varchar(55) DEFAULT '' NOT NULL,
        UNIQUE KEY id (id)
    ) $charset_collate;";

    require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
    dbDelta( $sql );

    add_option( 'jal_db_version', $jal_db_version );
}

Wednesday, October 29, 2014

How to include your css in wordpress plugin?

// register jquery and style on initialization


add_action('init', 'register_script');
function register_script() {
    wp_register_script( 'custom_jquery', plugins_url('plug/js/jquery.js'));

    wp_register_style( 'new_style', plugins_url('plug/css/style.css'));
}

// use the registered jquery and style above
add_action('wp_enqueue_scripts', 'enqueue_style');

function enqueue_style(){
   wp_enqueue_script('custom_jquery');

   wp_enqueue_style( 'new_style' );
}





//Link your CSS

<style type="text/css">
<?php include('css/style.css'); ?>
</style>