Sunday, 21 December 2014

Tuesday, 9 December 2014

Increase Media file upload size in Wordpress Multisite

In WordPress, Maximum upload file size will not change even when changed in the php.ini file.
Here are the steps to change the Maximum upload file size within WP admin:
1. At the top, hover over My Sites and then click Network Admin
2. At the left, hover over Settings and then click Network Settings.
3. Scroll to the bottom of the page and change the Max upload file size to whatever you would like in KB.
4. Click Save Changes.

To get Free assistance and any Query related to Wordpress, html ,css and responsive websites ....




Wednesday, 3 December 2014

PDO (PHP Data Object)

PDO(PHP Data Object)  : PDO is a PHP extension for accessing databases in PHP.

Advantages:
1) Security : In MYSQL connection we manually sanitise using mysql_real_escape_string() functions in order to avoid SQL injections. But with PDO this is all taken care for us and means we no longer have to worry about SQL injection.
2) Performance : PDO uses PHP 5′s OOP characteristics (Object Oriented Programming) so it is working with classes and objects. PDO is written in C and compiled into PHP providing a performance increase over solutions written in PHP.
3) PDO provides single interface across multiple databases. That means to easily migrate to a different database engine (SQLite, Oracle, MSSQL, ODBC, etc.)
4) We can use error handling in PDO by using try, catch and throw.

Connection Syntex:
$user = USER_NAME;
$pass = PASSWORD;
 $dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass);

 Exception handling in PDO:
  try {
    $dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass);
  }
  catch (PDOException $e) {
    print "Error!: " . $e->getMessage() . "<br/>";
    die();
 }

 Prepare query:

 Insert query:

 $sth = $dbh->prepare("INSERT INTO `table` (`id`, `title`) VALUES (:id, :title)");
 $sth->execute(array(':id'    => 123,':title' => 'I am the title'));

 Select Query:

 $sth = $dbh->prepare("SELECT `id`, `title` FROM `table` WHERE `id` > :country_id");
 $sth->execute(array(
    ':country_id' => 200
 ));
 $count = $sth->rowCount();

Thursday, 17 July 2014

CSS Media Queries For Common Devices

/* All Smartphones in portrait and landscape ----------- */
@media only screen 
and (min-device-width : 320px) 
and (max-device-width : 480px) {
/* YOUR STYLE GOES HERE */
}

/* All Smartphones in landscape ----------- */
@media only screen 
and (min-width : 321px) {
/* YOUR STYLE GOES HERE */
}

/* All Smartphones in portrait ----------- */
@media only screen 
and (max-width : 479px) {
/* YOUR STYLE GOES HERE */
}

/***** ANDROID DEVICES *****/

/* Android 240 X 320 ----------- */
@media only screen
and (max-width: 241px){
/* YOUR STYLE GOES HERE */
}

/* Android(Samsung Galaxy) in portrait 380 X 685 ----------- */
@media only screen
and (min-width: 375px)
and (max-width: 385px){
/* YOUR STYLE GOES HERE */
}

/* Android(Samsung Galaxy) in Landscape 685 X  380 ----------- */
@media only screen
and (min-width: 680px)
and (max-width: 690px){
/* YOUR STYLE GOES HERE */
}

/* Kindle Portrait 600 X 1024 ----------- */
@media only screen
and (min-width: 595px)
and (max-width: 610px){
/* YOUR STYLE GOES HERE */
}

/* Kindle Landscape 1024 X 600 ----------- */
@media only screen
and (min-width: 1000px)
and (max-width: 1030px){
/* YOUR STYLE GOES HERE */
}

/***** ALL GENERATION IPADS *****/

/* iPads in portrait and landscape----------- */
@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) {
/* YOUR STYLE GOES HERE */  
}

/* iPad in landscape----------- */
@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) 
and (orientation : landscape) {
/* YOUR STYLE GOES HERE */
}

/* iPad in portrait----------- */
@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) 
and (orientation : portrait){
/* YOUR STYLE GOES HERE */
}



/***** Retina IPAD 3 & 4*****/

/* Retina iPad 3 & 4 in portrait and landscape----------- */
@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px)
and (-webkit-min-device-pixel-ratio: 2){
/* YOUR STYLE GOES HERE */
}

/* Retina iPad 3 & 4 in landscape----------- */

@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) 
and (orientation : landscape)
and (-webkit-min-device-pixel-ratio: 2){
/* YOUR STYLE GOES HERE */
}

/* Retina iPad 3 & 4 in landscape----------- */

@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) 
and (orientation : portrait)
and (-webkit-min-device-pixel-ratio: 2){
/* YOUR STYLE GOES HERE */
}




/***** IPAD 1 & 2 (ALSO IPAD MINI)*****/

/* iPad 1 & 2 in portrait and landscape ----------- */
@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) 
and (-webkit-min-device-pixel-ratio: 1){
/* YOUR STYLE GOES HERE */
}

/* iPad 1 & 2 in landscape ----------- */
@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) 
and (orientation : landscape)
and (-webkit-min-device-pixel-ratio: 1)  {
/* YOUR STYLE GOES HERE */
}

/* iPad 1 & 2 in portrait ----------- */
@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) 
and (orientation : portrait) 
and (-webkit-min-device-pixel-ratio: 1){
/* YOUR STYLE GOES HERE */
}

/* Desktops and laptops ----------- */
@media only screen 
and (min-width : 1224px) {
/* YOUR STYLE GOES HERE */
}

/* Large screens ----------- */
@media only screen 
and (min-width : 1824px) {
/* YOUR STYLE GOES HERE */
}

/* Only iPhone 4 ----------- */
@media
only screen and (-webkit-min-device-pixel-ratio : 1.5),
only screen and (min-device-pixel-ratio : 1.5) {
/* YOUR STYLE GOES HERE */
}

Monday, 14 July 2014

Create your own Autocomplete for Adding Multiple emails using JQuery

<html>
<head>
<style>
#auto_email_to
{
    border:1px solid #cccccc;
    width:auto;
    font-family:verdana, arial, helvetica, sans-serif;
    font-size:15px;
    height:auto;
    margin-top:0px;
    list-style:none;
    position: absolute;   /*display:none;*/
    padding: 0;
    background-color: #EAEAEA;
    z-index:1;
    box-shadow:6px 6px 8px #cccccc;
}

#auto_email_to li
{
    height:25px;
}

#email_to
{
    width:800px;
}

.services li.selected{
    background-color:#636060;
    color:#ffffff;
}
</style>


<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js" type="text/javascript">
</script>
<script>


var email_to = ["Albert@tom_jerry123.com","Allen@tom_jerry123.com","Aladin@tom_jerry123.com","Nilesh@tom_jerry123.com","Dharmesh@tom_jerry123.com","Aakesh@tom_jerry123.com","Pankaj@tom_jerry123.com","Vijay@fakebook.com","Manoj@fakebook.com","Zahir@fakebook.com","Mukesh@fakebook.com","Kishor@fakebook.com","Sachin@fakebook.com","Rakesh@fakebook.com"];

$(document).ready(function(){

var seperator = "";


//alert(123);
if($("#email_to").length > 0)
    {
   
        $("#email_to").unbind('keyup').keyup(function(e){
            var str = $("#email_to").val();
       
            var last_char = str.slice(-1);
       
          
            if(last_char == ",")
            {
               
                seperator = ",";   
            }
            else if(last_char == ";")
            {
              
                seperator = ";";   
            }
       
           
       
            if(seperator == ",")
            {
                if(str.lastIndexOf(",") == -1)
                {
                    //var Index = "";

                }
                else
                {
                   
                    var Index = str.lastIndexOf(",")+1;
                }
   
            }
            else if(seperator = ";")
            {
                if(str.lastIndexOf(";") == -1)
                {
                    //var Index = "";
                   
                }
                else
                {
                   
                    var Index = str.lastIndexOf(";")+1;
                }
       
            }
       
            if(Index < str.length)
            {

               
                var result = str.substring(str.lastIndexOf(""+seperator+"") + 1);  
               
                if(e.keyCode == 13) 
                {//("Enter");
                   
                    var text_value = $("#email_to").val();
                    var sub_val = text_value.substring(0,text_value.lastIndexOf(""+seperator+""));
                    var my_value = $(".selected").attr('id');
                    var final_value = sub_val + seperator + " " + my_value;
                    if(my_value != undefined)
                    {
                        $( "#email_to" ).val(final_value);
                        $( "#email_to" ).focus();
                        $("#auto_email_to").slideUp();
                        $(".services").empty();
                    }
                }
                else if(e.keyCode == 38) 
                { //up
                    var selected = $(".selected");
                    $(".services li").removeClass("selected");
                        //alert(selected.prev().length);
                        // if there is no element before the selected one, we select the last one
                        if (selected.prev().length == 0) 
                        {
                            var child = selected.siblings().length + 1;
                            //alert(child);
                        $(".services li:nth-child("+child+")").addClass("selected");
                        } 
                        else 
                        { // otherwise we just select the next one
                        selected.prev().addClass("selected");
                        }
                        
                }
                else if(e.keyCode == 40) 
                { //down
                   
                    var selected = $(".selected");
                    $(".services li").removeClass("selected");
                   
                    if (selected.next().length == 0) 
                    {
                        $(".services li:nth-child(1)" ).addClass("selected");
                    } 
                    else 
                    {
                        selected.next().addClass("selected");
                    }
               
                }
                else
                {
                    call_email(result, "email_to", seperator);
                }
            }
            else
            {
           
                if(e.keyCode == 13) 
                { // enter
       
   
                    if ($(".services").is(":visible"))
                    {
       
                        my_value = $(".selected").attr('id');

                            $( "#email_to" ).val(my_value);
                            $(".product_class").empty();
                        $(".services").empty();
                        $("#auto_email_to").slideUp();
                        
                    }
                     else
                     {
                        $(".services").show();
                    }
                    //menuOpen = !menuOpen;
                 }

                else if(e.keyCode == 38) 
                { // up

                    var selected = $(".selected");
                    $(".services li").removeClass("selected");
                    
                    // if there is no element before the selected one, we select the last one
                    if (selected.prev().length == 0) 
                    {
                        var child = selected.siblings().length + 1;
                       
                    $(".services li:nth-child("+child+")").addClass("selected");
                    } 
                    else 
                    { // otherwise we just select the next one
                    selected.prev().addClass("selected");
                    }
                }

                else if(e.keyCode == 40) 
                { // down
                    var selected = $(".selected");
                    $(".services li").removeClass("selected");
                    if (selected.next().length == 0) 
                    {
                        $(".services li:nth-child(1)" ).addClass("selected");
                    } 
                    else 
                    {
                        selected.next().addClass("selected");
                    }
                  }
                  else
                  {
                      call_name("email_to");
                  }
            }
       
        });
       
    }
});


function call_email(value, param, seperator)
{
    //alert(seperator);
    $(".services").empty();
    var biller_name = value.toUpperCase().trim();
    //alert(biller_name + "  " + param);
    var container = "";
    $("#auto_"+param+"").empty();
    if(biller_name != "")
    {
        if(param == "email_to")
        {
            var j = 0;
            for(i=0;i<email_to.length;i++)
            {
                container = email_to[i].toUpperCase().toString();
               
                if(container.indexOf(biller_name) >= 0)http://jsfiddle.net/7418/hzZJA/1/
                {
                   
                    if(j == 0){var selected = 'selected';}else{var selected = 'abc';}
                    $("#auto_"+param+"").append("<li class='listing "+selected+"' id='"+email_to[i]+"'>"+email_to[i]+"</li>");               
                    j++;
                }
                else
                {
                    $(".services").hide();
                   
                }
            }
        }
       
        $("#auto_"+param+"").slideDown();
       
            $(".services li").mouseover(function() {
            //alert(param);
http://jsfiddle.net/7418/hzZJA/1/             $(".services li").removeClass("selected");
            $(this).addClass("selected");
            });
           
            $(".services li").click(function() {
               
                var text_value = $("#"+param+"").val();
                var sub_val = text_value.substring(0,text_value.lastIndexOf(""+seperator+""));
                //alert(sub_val);
                var my_value = $(this).attr('id');
               
                var final_value = sub_val + seperator + " " + my_value;
                    selectOption(final_value, param);
                    $("#"+param+"").focus();
                $(".services").empty();
                $("#auto_"+param+"").slideUp();
            });
           
    }
    else
    {
            $("#auto_"+param+"").slideUp();
    }
   
}


function call_name(param)
{
    $(".services").empty();
    //alert(param);
    var temp_name = $("#"+param+"").val().toUpperCase().trim();
    var container = "";
    $("#auto_"+param+"").empty();
    if(temp_name != "")
    {
        if(param == "email_to")
        {
            var j = 0;
            for(i=0;i<email_to.length;i++)
            {
                container = email_to[i].toUpperCase().toString();
               
                if(container.indexOf(temp_name) >= 0)
                {
                   
                    if(j == 0){var selected = 'selected';}else{var selected = 'abc';}
                    $("#auto_"+param+"").append("<li class='listing "+selected+"' id='"+email_to[i]+"'>"+email_to[i]+"</li>");               
                    j++;
                }
                else
                {
                    $("#auto_"+param+"").hide();
                }
            }
        }
       
           
           
        $(".services li").mouseover(function()
        {
            $(".services li").removeClass("selected");
            $(this).addClass("selected");
        });
       
        $(".services li").click(function() {
            var my_value = $(this).attr('id');   
                selectOption(my_value, param);
                $(".product_class").empty();
            $(".services").empty();
        });
        var my_width = $("#"+param+"").width() + 5;
   
        $("#auto_"+param+"").width(my_width);
        $("#auto_"+param+"").width(my_width);
        $("#auto_"+param+"").slideDown();
       
        if(param != "email_to")
        {
            $("#"+param+"").unbind('blur').blur(function() {
                var my_value = $(".selected").attr('id');
                var my_id = $(".selected").attr("value");
                if($("#"+param+"").val() == "")
                {
                    $("#"+param+"_id").val("");
                }
       
                    selectOption(my_value, param, my_id);
                $("#auto_"+param+"").slideUp();
                $(".services").empty();
            });
        }
       
           
    }
    else
    {
            $("#auto_"+param+"").slideUp();
    }
   
}

function selectOption(my_value, param, my_id)
{
   
    $( "#"+param+"" ).val(my_value);
    $( "#"+param+"_id" ).val(my_id);
    $("#auto_"+param+"").slideUp();
}

</script>
</head>
<h3>For separating Email addresses use "," or ";"</h3>
<input type="text" class="" id="email_to" value="" placeholder="Enter Email" autocomplete="off"/>
<ul class="services" id="auto_email_to">
                   
</ul>
</html>

Live Demo :

Wednesday, 9 July 2014

HTML5 canvas using JavaScript

The canvas is HTML5 element used to draw graphics using JavaScript. 

<!DOCTYPE html>
<html>
<body>
<canvas id="myCanvas" style="border:1px solid #000000;">Your browser does not support the HTML5 canvas tag.</canvas>

<script>
var c=document.getElementById('myCanvas');
var ctx=c.getContext('2d');
//ctx.fillStyle='#FF0000';

  for (var x = 0, y = 0; x < 150 && y < 200; x += 50, y += 37) {
var i = x+125;

var color ='FF0'+i;
//alert(color);
ctx.fillStyle='#'+color;
ctx.fillRect(x,y,60,60);
  }

</script>

</body>
</html>


Thursday, 3 July 2014

Fetch GooglePlus Feeds using PHP


<?php function fetchAPI($url) {

$content = '';

if (ini_get('allow_url_fopen') == true) {
$content = file_get_contents($url);
}
else {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url . $key);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$content = curl_exec($ch);
curl_close($ch);
}
return $content;
}


// Google+ ID
$googlePlusID = 'YOUR ID';
$url = "https://plus.google.com/YOUR ID/posts";
// Google+ API key
$key = 'DEVELOPER KEY';

$url = 'https://www.googleapis.com/plus/v1/people/' . $googlePlusID . '/activities/public?alt=json&pp=1&key=';

$content = fetchAPI($url . $key);

if ($content)
file_put_contents($cacheFile, $content);
if (!$content)
die('Failed to load G+ data');
$gplus = json_decode($content);

if (!$gplus)
die('Failed to decode G+ data');
echo "<pre>";
print_r($gplus);
die;


Sunday, 22 June 2014

File Upload and Delete multiple rows by selecting checkboxes using PHP

Index Page :
<html>
<head></head>
<body>
<form name="frm" method="post" action="submit.php" enctype="multipart/form-data">
<table>
<tr>
<td> Student Name </td>
<td><input type="text" name="stu_name"/><td>
<tr>
<tr>
<td> Student Email </td>
<td><input type="text" name="stu_email"/><td>
<tr>
<tr>
<td> Student Phone </td>
<td><input type="text" name="stu_phone"/><td>
<tr>
<tr>
<td> Student Photo </td>
<td><input type="file" name="stu_photo"/><td>
<tr>
<tr colspan="2">
<td><input type="submit" value="submit data" name="submit"></td>
</tr>
</table>
</form>
<form name="frm1" method="post" action="submit.php" enctype="multipart/form-data">
<table>
<tr>
<td><input type="checkbox" name="check_all"/>
<td>ID</td>
<td> Name</td>
<td> Email</td>
<td> phone</td>
<td>photo </td>
</tr>
<?php
$con = mysql_connect("localhost","root","");
mysql_select_db("pan_test",$con);
$query = mysql_query("select * from stu_info");
while($row = mysql_fetch_array($query)){
$id = $row['id'];
$name = $row['name'];
$email = $row['email'];
$phone = $row['phone'];
$photo = $row['photo'];
echo "<tr>";
echo "<td><input type='checkbox' name='checkbox[]' value='$id'/></td>";
echo "<td>$name</td>";
echo "<td>$email</td>";
echo "<td>$phone</td>";
//echo "<td><img src='uploads/$photo'/><td>";
echo "</tr>";
}

?>
<tr colspan="2">
<td><input type="submit" value="submit data" name="submit1"></td>
</tr>
</body>
</html>

submit.php

<?php
$con = mysql_connect("localhost","root","");
mysql_select_db("pan_test",$con);
if($_REQUEST['submit']){
$name= $_REQUEST['stu_name'];
if(empty($name)){
echo "missing";
}
$mail= $_REQUEST['stu_email'];
$phone=$_REQUEST['stu_phone'];
$photo= $_FILES['stu_photo'] ['name'];
$target = 'uploads/'.basename($_FILES['stu_photo'] ['name']);
move_uploaded_file($_FILES['stu_photo'] ['tmp_name'],$target);

$query = mysql_query("insert into stu_info(name,email,phone,photo) values('$name','$mail','$phone','$photo')");
header('location: index.php');
}
else if($_REQUEST['submit1']){
print_r($_REQUEST);
$checkbox= $_REQUEST['checkbox'];
for($i=0;$i<count($_REQUEST['checkbox']);$i++){
echo $id= $checkbox[$i];
$query = mysql_query("delete from stu_info where id=$id");

}
}

?>

Saturday, 21 June 2014

Database Connectivity using Type I - JDBC Driver in Java(J2SE)

What is JDBC?

  • JDBC(Java DataBase Connectivity) is used for connecting to different database by which user can shift from one database to another database very easily in platform independent manner.
  • JDBC contains set of functions & specification in the form of packages i.e.:
    • java.sql.*--Core SQL Package
    • javax.sql.*--Extended SQL Package
  • JDBC Driver act like an interface between front end application and back end database.
  • There are four types of JDBC Driver
    • Type I-ODBC(Open DataBase Connectivity) Bridge Driver 
    • Type II-Java Native Interface Driver
    • Type III-Net Protocol Driver
    • Type-IV-Native Protocol Drover
  • Type I Driver, there exist an implementation class by which user can be able to connect to different database.
  • This implementation class, named JdbcOdbcDriver.class is provided within rt.jar file.

Connecting to any Database:-

Step 1) Loading a Driver: 
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Step 2) Getting Connection: 
Connection con = DriverManager.getConnection("<URL>","<UserName>","<Password>");
Step 3) Create Statement Object:

Statement st = con.createStatement();
Step 4) Prepare a query and execute the query at backend database.

  • ResultSet rs = st.executeQuery("<SQL SELECT command>");
  • boolean flag = st.execute("<SQL Non-SELECT command>");
  • int x = st.executeUpdate("<SQL DML command>");

Step 5) Close all connections: 
st.close();
con.close();

Sample JDBC code for this demonstration:

import java.sql.*;

class DBConnectivity
{
public static void main( String [] args)
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection("jdbc:odbc:OracleDSN","scoot","tiger");
Statement st = conn.createStatement();
boolean flag = st.execute("create table student(ID varchar2(5), NAME varchar2(30), MARKS number(5))");
int x = st.executeUpdate("inser into stud values('101','Pallavi',879)");
ResultSet rs = st.executeQuery("<SELECT ID,NAME,MARKS from student>");
while (re.nwex())
{
logout("ID:-"+rs.getString(1)+"\t");
logout("NAME:-"+rs.getString(2)+"\t");
logout("MARKS:-"+rs.getInt(3)+"\n");
}
}

public void logout(String msg)
{
System.out.println(msg);
}

}

Note: Here "OracleDSN" is User Created DSN (Data Source Name), in Administrative Tools-->Data Source

Wednesday, 18 June 2014

Custom post type having same taxonomy in wordpress

Register custom post type and taxonomy

// function.php code

register_post_type('test1',
                      array(
                        'labels' => array(
                                     'name' => _x('Test1'),
                                     'singular_name' => _x('Test1'),
                                     'add_new' => _x('Add Test1', 'test1'),
                                     'add_new_item' => __('Add New Test1'),
                                     'edit_item' => __('Edit Test1'),
                                     'new_item' => __('New Test1'),
                                     'view_item' => __('View Test1'),
                                     'search_items' => __('Search Test1'),
                                     'not_found' =>  __('No Test1'),
                                     'not_found_in_trash' => __('No Test1 found in Trash'),
                                     'parent_item_colon' => ''
                                   ),
                        'public' => true,
                        'has_archive' => true,
                        'publicly_queryable' => true,
                        'query_var' => 'social_reporting',
                        'rewrite' => array('slug'=>'test1', 'with_front'=>false),
                        'capability_type' => 'post',
                        'hierarchical' => true,
'supports' => array('title', 'editor', 'page-attributes', 'thumbnail','taxonomy'),
'taxonomies' => array('post_tag')
                     
                 ));
 // custom post type for Video
  register_post_type('video',
                      array(
                        'labels' => array(
                                     'name' => _x('Video'),
                                     'singular_name' => _x('Video'),
                                     'add_new' => _x('Add Video', 'video'),
                                     'add_new_item' => __('Add New Video'),
                                     'edit_item' => __('Edit Video'),
                                     'new_item' => __('New Video'),
                                     'view_item' => __('View Video'),
                                     'search_items' => __('Search Video'),
                                     'not_found' =>  __('No Video found'),
                                     'not_found_in_trash' => __('No Video in Trash'),
                                     'parent_item_colon' => ''
                                   ),
                        'public' => true,
                        'has_archive' => true,
                        'publicly_queryable' => true,
                        'query_var' => 'video',
                        'rewrite' => array('slug'=>'video', 'with_front'=>false),
                        'capability_type' => 'post',
                        'hierarchical' => true,
'supports' => array('title', 'editor', 'page-attributes', 'thumbnail','taxonomy'),
'taxonomies' => array('post_tag')
                     
                 ));
}
add_action( 'init', 'initialize_autos_post_types' );
//custom taxonomy
register_taxonomy('pan_taxonomy', array('test1','video'),  array(
'label' => __('Add Categories'),
'singular_label' => __('Add Category'),
'hierarchical' => true,
'query_var' => 'pan_taxonomy',
'rewrite' => false,
'public' => true,
'show_ui' => true,
'show_in_nav_menus' => false,
        ));


To fetch custom taxonomy post 

// page.php code

<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
        $post_type = array('test1','video');
        $loop = new WP_Query( array( 'post_type' => $post_type, 'posts_per_page' => -1, 'orderby'=>'date', 'paged'=>$paged ) );
?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
       <article>
           <div class="right_blog_post">
                        <?php the_title( '<h2 class="entry-title"><a href="' . get_permalink() . '" title="' . the_title_attribute( 'echo=0' ) . '" rel="bookmark">', '</a></h2>' ); ?>
<div class="entry-content">
                         <?php
                         the_excerpt();
                         ?>
    </div>
                    </div>
                </article>
  <?php endwhile; ?>


Monday, 16 June 2014

Create your own Autocomplete for textbox using JQuery

<html>
<head>
<style>
#auto_my_name
{
    border:1px solid #cccccc;
    width:auto;
    font-family:verdana, arial, helvetica, sans-serif;
    font-size:15px;
    height:auto;
    margin-top:0px;
    list-style:none;
    position: absolute;   /*display:none;*/
    padding: 0;
    background-color: #EAEAEA;
    z-index:1;
    box-shadow:6px 6px 8px #cccccc;
}

#auto_my_name li
{
    height:25px;
}

#my_name
{
    width:100px;
}

.services li.selected{
    background-color:#636060;
    color:#ffffff;
}
</style>


<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js" type="text/javascript">
</script>
<script>

var my_name = ["Albert","Allen","Aladin","Nilesh","Dharmesh","Aakesh","Pankaj","Vijay","Manoj","Zahir","Mukesh","Kishor","Sachin","Rakesh"];
//Values for autocomplete list

$(document).ready(function(){

$("#my_name").unbind('keyup').keyup(function(e){
       
            if(e.keyCode == 13)
            {// Enter
                if ($(".services").is(":visible"))
                {
           
                    my_value = $(".selected").attr('id');
                    var my_id = $(".selected").attr("value");
                        $( "#my_name" ).val(my_value);
                    $(".services").empty();
                    $("#auto_my_name").slideUp();
                   
                }
                else
                {
                        $(".services").show();
                }
             }
       
            else if(e.keyCode == 38)
            { // up

                var selected = $(".selected");
                $(".services li").removeClass("selected");
                // if there is no element before the selected one, we select the last one
                if (selected.prev().length == 0)
                {
                    var child = selected.siblings().length + 1;
                $(".services li:nth-child("+child+")" ).addClass("selected");
                }
                else
                { // otherwise we just select the next one
                selected.prev().addClass("selected");
                }
            }
       
            else if(e.keyCode == 40)
            { // down
                var selected = $(".selected");
                $(".services li").removeClass("selected");
                if (selected.next().length == 0)
                {
                    $(".services li:nth-child(1)" ).addClass("selected");
                }
                else
                {
                    selected.next().addClass("selected");
                }
              }
             
              else
              {
                  call_name("my_name");
                 
              }
    });
       
});
   
   
function call_name(param)
{
    $(".services").empty();
    var temp_name = $("#"+param+"").val().toUpperCase().trim();
    var container = "";
    $("#auto_"+param+"").empty();
    if(temp_name != "")
    {
        if(param == "my_name")
        {
            var j = 0;
            for(i=0;i<my_name.length;i++)
            {
                container = my_name[i].toUpperCase().toString();
               
                if(container.indexOf(temp_name) >= 0)
                {
                   
                    if(j == 0){var selected = 'selected';}else{var selected = 'abc';}
                    $("#auto_"+param+"").append("<li class='listing "+selected+"' id='"+my_name[i]+"'>"+my_name[i]+"</li>");               
                    j++;
                }
                else
                {
                    $("#auto_"+param+"").hide();
                }
            }
        }
       
           
           
        $(".services li").mouseover(function()
        {
            $(".services li").removeClass("selected");
            $(this).addClass("selected");
        });
       
        $(".services li").click(function() {
            var my_value = $(this).attr('id');   
                selectOption(my_value, param);
                $(".product_class").empty();
            $(".services").empty();
        });
        var my_width = $("#"+param+"").width() + 5;
   
        $("#auto_"+param+"").width(my_width);
        $("#auto_"+param+"").width(my_width);
        $("#auto_"+param+"").slideDown();
       
       
        $("#"+param+"").unbind('blur').blur(function() {
            var my_value = $(".selected").attr('id');
            var my_id = $(".selected").attr("value");
            if($("#"+param+"").val() == "")
            {
                $("#"+param+"_id").val("");
            }
           
                selectOption(my_value, param, my_id);
            $("#auto_"+param+"").slideUp();
            $(".services").empty();
        });
       
           
    }
    else
    {
            $("#auto_"+param+"").slideUp();
    }
   
}

function selectOption(my_value, param, my_id)
{
   
    $( "#"+param+"" ).val(my_value);
    $( "#"+param+"_id" ).val(my_id);
    $("#auto_"+param+"").slideUp();
}

</script>
</head>
<input type="text" class="" id="my_name" value="" placeholder="Enter Name" autocomplete="off"/>
<ul class="services" id="auto_my_name">
                   
</ul>
</html>

Demo : 

A Simple way to Generate Random number in Java

Math.Random class

In Java Programming, Math.Randoms class generates random integers, doubles, longs and so on, in various ranges.

To generate a series of random numbers as a unit, you need to use a single Random object - do not create a new Random object for each new random number.

Following example shows this:




import java.util.Random;
/** Generate 10 random integers in the range 0..99. */

public class RandomInteger 

{

public static final void main(String... aArgs)
{
log("Generating 10 random integers in range 0..99.");
//note a single Random object is reused here Random randomObj = new Random();
for (int idx = 1; idx <= 10; ++idx)

{
int randomInt = randomGenerator.nextInt(100);

log("Generated : " + randomInt);
}
log("Done.");
}
private static void log(String aMessage)

{
System.out.println(aMessage);
}


}






Sunday, 15 June 2014

Hello World in Ember.js

Quick Start

>>> Step 1 : Create a html file and include files like ember.js and other dependencies.

    < script src='http://code.jquery.com/jquery-1.10.2.min.js'></script>
    <script src='http://builds.handlebarsjs.com.s3.amazonaws.com/handlebars-1.0.0.js'></script>
    <script src='http://builds.emberjs.com/tags/v1.3.0/ember.js'></script>

>>>Step 2: Create a view using handlebars template
It replaces body of html page
 
    <script type='text/x-handlebars' data-template-name='application'>
         <h1>{{appName}}</h1>
    </script>

>>>Step 3: Initialize ember application

   <script type='text/javascript'>
        App = Ember.Application.create({});
    </script>

>>>Step 4: Controller
Template is named as 'application'. So, the name of a controller should be 'ApplicationController'.

   <script type='text/javascript'>
        App.ApplicationController = Ember.Application.extend({
             message: 'Hello World'
        });
    </script>


Thursday, 12 June 2014

PHP Code for Locating Train stations, ATM's, Mall's and many things Nearby Using Google Map API

<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    <meta charset="utf-8">

<style>
html, body, #googleMap
      {
        height: 100%;
        margin: 0px;
        padding: 0px;      
      }
     
.controls
      {
          position: absolute;
          z-index: 10;
        margin-top: 16px;
        margin-left:100px;
        border: 1px solid transparent;
        border-radius: 2px 0 0 2px;
        box-sizing: border-box;
        -moz-box-sizing: border-box;
        height: 32px;
        outline: none;
        box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
      }
     
 #country_name
      {
          box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
          position: absolute;
        background-color: #fff;
        padding: 0 11px 0 13px;
        margin-left:100px;
        margin-top:50px;
        border: 1px solid transparent;
        border-radius: 2px 0 0 2px;
        box-sizing: border-box;
        -moz-box-sizing: border-box;
        height: 32px;
        outline: none;
        width: 400px;
        font-family: Roboto;
        font-size: 15px;
        font-weight: 300;
        text-overflow: ellipsis;
        z-index: 10;
      }
     
  #coord0
      {
          box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    position: absolute;
    z-index: 10;
    margin-left:100px;
        margin-top:760px;
        width:1000px;
      }
     
  #selection
      {
          background-color: #fff;
          box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
          position: absolute;
    z-index: 10;
    margin-left:100px;
        margin-top:30px;
      }
</style>
   
<script src="jquery-1.7.1.js" type="text/javascript">
</script>
<script src="jquery.fancybox-1.3.4.pack.js" type="text/javascript">
</script>
<!--script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false">
</script-->
<script type="text/javascript"
        src="https://maps.googleapis.com/maps/api/js?v=3.exp&amp;sensor=true&amp;libraries=places,drawing"></script>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<link rel="stylesheet" href="jquery.fancybox-1.3.4.css"/>

<script>
var map;
var infowindow;
var new_map;
var center;
var place_name = [];
var tubes;
var place_type;
var remove_marker = [];
////////////////////////////////////////
function initialize()
{
  mapProp = {
      center:new google.maps.LatLng(23.8989,12.4731),
      zoom:4,
      mapTypeId:google.maps.MapTypeId.ROADMAP
  };
 
 
    
    
    map = new google.maps.Map(document.getElementById("googleMap")
  ,mapProp);
 
  $(window).click(function(){
 
      place_type = $("#place_type").val();
  });
 
 
  $(window).keydown(function(event){
        if(event.keyCode == 13)
        {
            place_type = $("#place_type").val();
          ///event.preventDefault();
         //return false;
        }
      });
 
 
  //-----------------------------------------------------------------//
  var input = /** @type {HTMLInputElement} */(
      document.getElementById('country_name'));
 
  //map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);
 
  var options = {
  types: ['(cities)'],
  componentRestrictions: {country: "in"}
 };
 
 
  var autocomplete = new google.maps.places.Autocomplete(input, options);
  //autocomplete.bindTo('bounds', map);
 
  var infowindow = new google.maps.InfoWindow();
  var marker = new google.maps.Marker({
    map: map
  });

 
  google.maps.event.addListener(autocomplete, 'place_changed', function() {
    infowindow.close();
    marker.setVisible(true);
   
    google.maps.event.addListener(autocomplete, 'resize');
    
    
    var place = autocomplete.getPlace();
    google.maps.event.trigger(map, 'resize');
    
    for (var i = 0; i < remove_marker.length; i++) {

        var marker1 = new google.maps.Marker
          ({
            map: map,
            position: remove_marker[i]
          });
 
          marker1.setMap(null);
    }
    
    if (!place.geometry) {
        
      return;
    }

    // If the place has a geometry, then present it on a map.
    if (place.geometry.viewport)
    {
        map.fitBounds(place.geometry.viewport);
        //console.log(place.geometry);
        var getbounds = map.getCenter(place.geometry.location);
        //alert(place_type);
        var newcenter = [];
        newcenter[0] = place.geometry.location.lat();
        newcenter[1] = place.geometry.location.lng();
        //alert("My center"+newcenter);
        
        var getcenter = new google.maps.LatLng(newcenter[0], newcenter[1]);
        //alert("GEOMETRY"+getcenter);
        
        var request = {
        location: getcenter,
        radius: '1609.34',
        types: [""+place_type+""]
        };
        
        var circle = new google.maps.Circle({
              map: map,
              strokeWeight: 0.5,
              strokeColor: '#3FAA3A',
              radius: 2000.34,    // 1 mile in metres
              fillColor: '#64F25E',
              center: getcenter
            });

        //alert("Your Center"+request);
        service = new google.maps.places.PlacesService(map);
        service.nearbySearch(request, callback);
 
        }
    else
    {
    
        var newcenter = [];
        newcenter[0] = place.geometry.location.lat();
        newcenter[1] = place.geometry.location.lng();
        //alert("My center"+newcenter);
        //alert(place_type);    
        var getcenter = new google.maps.LatLng(newcenter[0], newcenter[1]);
        //alert("Your Center"+getcenter);
        
        
        var request = {
        location: getcenter,
        radius: '1609.34',
        types: [""+place_type+""]
        };

        var circle = new google.maps.Circle({
              map: map,
              strokeWeight: 0.5,
              strokeColor: '#3FAA3A',
              radius: 2000.34,    // 1 mile in metres
              fillColor: '#64F25E',
              center: getcenter
            });

        service = new google.maps.places.PlacesService(map);
        service.nearbySearch(request, callback);
    
  
    }
    marker.setIcon(/** @type {google.maps.Icon} */({
      url: place.icon,
      size: new google.maps.Size(71, 71),
      origin: new google.maps.Point(0, 0),
      anchor: new google.maps.Point(17, 34),
      scaledSize: new google.maps.Size(35, 35)
    }));
    marker.setPosition(place.geometry.location);
    marker.setVisible(true);

    var address = '';
    if (place.address_components) {
            //alert(place.address_components[1].short_name);
            address = [
                (place.address_components[0] && place.address_components[0].short_name || ''),
                (place.address_components[1] && place.address_components[1].short_name || ''),
                (place.address_components[2] && place.address_components[2].short_name || '')
                ].join(' ');
            //alert("ADDRESS: "+address);
        
    }

    infowindow.setContent('<div><strong>' + place.name + '</strong><br>' + address);
    infowindow.open(map, marker);
 
 });
 
}
  //-----------------------------------------------------------------//



//------------------------FUNCTION CALLBACK FOR PLOTING MARKERS OF NEARBY SEARCH---------------------------------//

function callback(results, status) {
    var area_name = document.getElementById('coord0');


  if (status == google.maps.places.PlacesServiceStatus.OK) {
    //alert(status);
    
    console.log(results);
     var placelat = results[0].geometry.location.lat();
    var placelng = results[0].geometry.location.lng();
    
    var center1 = new google.maps.LatLng(placelat,placelng);
    //alert(placelat+", "+placelng);
    
    for (var i = 0; i < results.length; i++) {
      createMarker(results[i]);
            remove_marker.push(results[i].geometry.location);
      place_name.push(results[i].name);
    }
    
    map.setZoom(14);
    map.setCenter(center1);
    //alert(tubes);
    tubes = "";
    //alert(tubes);
    //alert(place_name);
    area_name.value = place_name;
    place_name = [];
    /*if (results)
    {
        for (i in results)
        {
          results[i].setMap(null);
        }
        results.length = 0;
    }*/
    //alert(place_name);
  }
  else
  {
    area_name.value = place_name;
  }
}


function createMarker(place) {
    var placelat = place.geometry.location.lat();
    var placelng = place.geometry.location.lng();
 
 
 
  var center1 = new google.maps.LatLng(placelat,placelng);
 
  infowindow = new google.maps.InfoWindow();
 
  tubes = new google.maps.Marker({
    map: map,
    position: place.geometry.location
  });
 
  tubes.setMap(map);
 
  google.maps.event.addListener(tubes, 'click', function() {
    infowindow.setContent(place.name);
    infowindow.open(map, this);
  });

 
}



function removeMarker(place) {
    var placelat = place.lat();
    var placelng = place.lng();
 
 
  alert(place);
  var center1 = new google.maps.LatLng(placelat,placelng);
 
  infowindow = new google.maps.InfoWindow();
 
  tubes = new google.maps.Marker
  ({
    map: map,
    position: place
  });
 
  tubes.setMap(null);
 
}


//------------------------FUNCTION CALLBACK FOR PLOTING MARKERS OF NEARBY SEARCH---------------------------------//


 google.maps.event.addDomListener(window, 'load', initialize);

</script>
</head>
<body>

<textarea id="coord0" width="700"></textarea><br>
<div id="selection">
Select Your Place Type
<select id="place_type">
    <option value="airport">Airpot</option>
    <option value="amusement_park">Amusement_park</option>
    <option value="aquarium">Aquarium</option>
    <option value="art_gallery">Art_gallery</option>
    <option value="atm">ATM</option>
    <option value="bakery">Bakery</option>
    <option value="bank">Bank</option>
    <option value="bar">Bar</option>
    <option value="beauty_salon">Beauty_salon</option>
    <option value="bicycle_store">Bicycle_store</option>
    <option value="book_store">Book_store</option>
    <option value="bowling_alley">Bowling_alley</option>
    <option value="bus_station">Bus_station</option>
    <option value="cafe">Cafe</option>
    <option value="car_dealer">Car_dealer</option>
    <option value="car_rental">Car_rental</option>
    <option value="car_repair">Car_repair</option>
    <option value="car_wash">Car_wash</option>
    <option value="casino">Casino</option>
    <option value="cemetery">Cemetery</option>
    <option value="church">Church</option>
    <option value="city_hall">City_hall</option>
    <option value="clothing_store">Clothing_store</option>
    <option value="convenience_store">Convenience_store</option>
    <option value="courthouse">Courthouse</option>
    <option value="dentist">Dentist</option>
    <option value="department_store">Department_store</option>
    <option value="doctor">Doctor</option>
    <option value="electrician">Electrician</option>
    <option value="electronics_store">Electronics_store</option>
    <option value="embassy">Embassy</option>
    <option value="establishment">Establishment</option>
    <option value="fire_station">Fire_station</option>
    <option value="florist">Florist</option>
    <option value="food">Food</option>
    <option value="funeral_home">Funeral_home</option>
    <option value="furniture_store">Furniture_store</option>
    <option value="gas_station">Gas_station</option>
    <option value="general_contractor">General_contractor</option>
    <option value="grocery_or_supermarket">Grocery_or_supermarket</option>
    <option value="gym">Gym</option>
    <option value="hair_care">hair_care</option>
    <option value="hardware_store">hardware_store</option>
    <option value="health">health</option>
    <option value="hindu_temple">hindu_temple</option>
    <option value="home_goods_store">home_goods_store</option>
    <option value="hospital">hospital</option>
    <option value="insurance_agency">insurance_agency</option>
    <option value="jewelry_store">jewelry_store</option>
    <option value="laundry">laundry</option>
    <option value="lawyer">lawyer</option>
    <option value="library">library</option>
    <option value="liquor_store">liquor_store</option>
    <option value="local_government_office">local_government_office</option>
    <option value="locksmith">locksmith</option>
    <option value="lodging">lodging</option>
    <option value="meal_delivery">meal_delivery</option>
    <option value="meal_takeaway">meal_takeaway</option>
    <option value="mosque">mosque</option>
    <option value="movie_rental">movie_rental</option>
    <option value="museum">museum</option>
    <option value="night_club">night_club</option>
    <option value="movie_theater">movie_theater</option>
    <option value="painter">painter</option>
    <option value="park">park</option>
    <option value="pet_store">pet_store</option>
    <option value="pharmacy">pharmacy</option>
    <option value="physiotherapist">physiotherapist</option>
    <option value="police">police</option>
    <option value="post_office">post_office</option>
    <option value="restaurant">restaurant</option>
    <option value="school">school</option>
    <option value="shopping_mall">shopping_mall</option>
    <option value="shoe_store">shoe_store</option>
    <option value="spa">spa</option>
    <option value="stadium">stadium</option>
    <option value="store">store</option>
    <option value="subway_station">subway_station</option>
    <option value="synagogue">synagogue</option>
    <option value="taxi_stand">taxi_stand</option>
    <option value="train_station">train_station</option>
    <option value="travel_agency">travel_agency</option>
    <option value="university">university</option>
    <option value="veterinary_care">veterinary_care</option>
     <option value="zoo">zoo</option>
</select>
</div><br>
<input type="text" id="country_name" >

<div id="googleMap">
    
</div>

</body>
</html>