Friday 25 July 2014

show featured image to the beginning of each post if added any or show default post image

<?php



function easy_the_content_filter( $content ) {


        // Add image to the beginning of each post. if any featured image is added by  author than show the  featured  image otherwise  show  the  common image for all post  if no featured image is set by author.
       if ( is_singular('post') && has_post_thumbnail()) {
        $thumbnail = get_the_post_thumbnail();

        $content = $thumbnail . $content;
       
        }
        else
        {
            $content = sprintf('<img class="post-icon" src="%s/images/php.jpg" alt="Post icon" title="" width="100"/>%s',get_bloginfo( 'stylesheet_directory' ),$content );
        }

    // Returns the content.
    return $content;
}


?>

Add image to the beginning of each post in wordpress

<?php



function easy_the_content_filter( $content ) {


        // Add image to the beginning of each page

            $content = sprintf('<img class="post-icon" src="%s/images/php.jpg" alt="Post image" title="" width="100"/>%s',get_bloginfo( 'stylesheet_directory' ),$content );
     

    // Returns the content.
    return $content;
}


?>

Add Word Limit to Wordpress Posts

<?php


//Add Word Limit to Posts

add_filter("the_content", "easy_custom_filter");

  function easy_custom_filter($content)
  {

    return substr($content, 0, 100);
   // return a subset of it
  }


?>

Show category images on single product page

<?php
//Show category images on single product page

$terms = get_the_terms( $post->ID, 'product_cat' );// get the post categories ids

  foreach ( $terms as $term ) // traverse all post category deails
{
        $category_name = $term->name;
        $category_thumbnail = get_woocommerce_term_meta($term->term_id, 'thumbnail_id', true);
        $image = wp_get_attachment_url($category_thumbnail);
        echo '<img src="'.$image.'">';
    }
   

?>

How to enable menu support in wordpress

<?php
//How to enable menu support in WordPress theme

function easy_enable_menu()
{
    add_theme_support( 'menus' );   
}

add_action( 'init', 'easy_enable_menu', 10 );

?>

How to remove bulk edit options

<?php


    //How to remove bulk edit options

    add_filter( 'bulk_actions-' . 'edit-post', '__return_empty_array' );
?>

Thursday 17 July 2014

how to create a custom post type in wordpress

<?php

/// put this code into your theme functions.php file 
add_action('init', 'easy_register_post_type');  //  hook  our function with Wordpress  process/stage

function easy_register_post_type() {

register_post_type(
    'products', array(
        'labels' => array(
            'name' => 'Products',
            'singular_name' => 'Product',
            'add_new' => 'Add new product',
            'edit_item' => 'Edit product',
            'new_item' => 'New product',
            'view_item' => 'View product',
            'search_items' => 'Search product',
            'not_found' => 'No products found',
            'not_found_in_trash' => 'No products found in Trash'
        ),
        'public' => true,
        'supports' => array('title',
           'title',
            'editor',
            'excerpt',
            'custom-fields',
            'revisions',
            'thumbnail'
        ),
        'has_archive' => true,
        'taxonomies' => array()
    )
);
}

?>

how to set new post thumbnail size in wordpress

<?php
//how to  set new post thumbnail size in wordpress

// set any size with your requirement  for the  thumbnail image

// add this code into your functions.php file

set_post_thumbnail_size( 210, 210, true );

?>

How to display custom post meta in wordpress

<?php
// To get the price of a random product we will need to know the ID
   $product_id=101;
    $price = get_post_meta( $product_id, 'product_price', true );

echo $price

?>   

Friday 11 July 2014

Top 20 Websites Making The Most Money

Top 20 Websites Making The Most Money



20. LinkedIn - $215,200,000 $7 per second
19. ClickBank - $350,000,000 $11 per second
18. Yandex - $439,700,000 $14 per second
17. Orbitz - $757,500,000 $24 per second
16. Groupon - $760,000,000 $24 per second
15. Taobao - $774,210,000 $25 per second
14. Zynga - $850,000,000 $27 per second
13. Skype - $860,000,000 $27 per second
12. Overstock - $1,100,000,000 $35 per second
11. Baidu - $1,199,000,000 $38 per second
10. Facebook - $2,000,000,000 $63 per second
9. NetFlix - $2,160,000,000 $68 per second
8. AOL - $2,417,000,000 $77 per second
7. Priceline – $3,072,240,000 $97 per second
6. Expedia, Inc. - $3,348,000,000 $106 per second
5. Alibaba - $5,557,600,000 $176 per second
4. Yahoo! - $6,324,000,000 $200 per second
3. eBay - $9,156,000,000 $290 per second
2. Google - $29,321,000,000 $929 per second
1. Amazon – $34,204,000,000 $1,084 per second



Sunday 29 June 2014

list of some Important Company's Founders



Here is list of some  Important Company's Founders

1) Founder of Bluetooth – Ericsson
2)
Founder of Microsoft – Bill Gates and Paul Allen
3)
Founder of Apple Computers – Steve Jobs
4) Father of  Computer – Charles Babbage
5) Father of  C Language – Dennis Ritchie
6) Founder of Email – Shiva Ayyadurai
7) Founder of Google – Larry Page and Sergey Brin
8) Founder of Internet – Vint Cerf
9) Father of  Java- James Gosling
10) Father of JQuery – John Resig
11) Founder of Keyboard – Christoper Latham Sholes
12)
Founder of Artificial Intelligence – John McCarthy
13) Founder of Mobile Phones – Martin Cooper
14) Founder of Mouse – Douglas Engelbart
15) Founders of Oracle – Ed Oates, Larry Ellison, Bob Miner
16) Founder of PHP – Rasmus Lerdorf
17) Founder of USB – Ajay V.Bhatt
18) Founder of WWW – Tim Berners-Lee
19) Founder of Yahoo – Jurry Yang and David Filo

Friday 16 May 2014

How to upload & Save Files with new name




<?php

 /* 
   //files array details
    $_FILES['easyfile']['name'] - the actual name of the uploaded file.

    $_FILES['easyfile']['size'] - the size in bytes of the uploaded file.

    $_FILES['easyfile']['tmp_name']- the uploaded file in the temporary directory on the web server.
   
    $_FILES['easyfile']['type'] - the MIME type of the uploaded file. file type like image,documnet,excel file

    $_FILES['easyfile']['error'] - the error code associated with this file upload.

*/
$msg="";
$upload_limit=1024000;
$valid_file=false;
echo $dirpath = dirname(__FILE__);
if (isset($_POST['submit']))
{

if($_FILES['easyfile']['name'])
{
    //if no errors...
    if(!$_FILES['easyfile']['error'])
    {
   
    //here is file destils
   
    echo "<pre>";
    print_r($_FILES);
    echo "</pre>";
   
    if($_FILES['easyfile']['size'] < $upload_limit ) //can't be larger than  upload limit
        {
            $valid_file = true;
           
        }else
        {

            $msg = 'Your file size is to big.';
        }
       
        //if the file has passed the test
        if($valid_file)
        {
            echo $file_new_name =  time()."_".strtolower($_FILES['easyfile']['name']); //rename your file

            //move/copy it to where we want it to be

            move_uploaded_file($_FILES['easyfile']['tmp_name'], $dirpath.'/uploads/'.$file_new_name);

            $msg = 'Congratulations!  Your file was upload successfully!.';
        }
   
   
    }
}

}// if submit button is hit

if ($msg!="")
echo $msg;
?>


<form action="" method="post" enctype="multipart/form-data">
    Your file: <input type="file" name="easyfile" size="40" />
    <input type="submit" name="submit" value="Submit" />
</form>

File Uploading in PHP

<?php

if (isset($_POST['submit']))
{


if($_FILES['easyfile']['name'])
{
    //if no errors...
    if(!$_FILES['easyfile']['error'])
    {
   
    //here is file destils
   
    echo "<pre>";
    print_r($_FILES);
    echo "</pre>";
   
   
    }
}

}// if submit button is hit

?>


<form action="" method="post" enctype="multipart/form-data">
    Your file: <input type="file" name="easyfile" size="40" />
    <input type="submit" name="submit" value="Submit" />
</form>

List files in directory using PHP

<?php

//List files in directory using PHP

$dirpath = dirname(__FILE__);// path to directory
if(is_dir($$dirpath))
{
    if($handle = opendir($$dirpath))
    {
        while(($file = readdir($handle)) !== false)
        {
            if($file != "." && $file != ".." && !is_dir($file))
            {
                echo $file.'<br/>';
            }
        }
        closedir($handle);
    }
}

?>

Wednesday 7 May 2014

Get country information by ip address in php

<?php
function get_easy_visitor_country($ip_address)
{
    if (!$ip_address)
     $ip_address=$_SERVER['REMOTE_ADDR'];
   
     $geopluginURL='http://www.geoplugin.net/php.gp?ip='.$ip_address;
     $addrDetailsArr =@unserialize(file_get_contents($geopluginURL));
      easy_debug($addrDetailsArr);
     $result=$addrDetailsArr['geoplugin_countryCode'];
    return $result;
}



function easy_debug($obj)
{

echo "<pre>";
     print_r(  $obj);
     echo "</pre>";
 
}


echo "country code ".visitor_country('27.255.252.191');
?>

Get Current Dollar Rate with INR

<?php
function current_rate($price=1)
{
  
        $url  = "http://www.google.com/finance/converter?a=$price&from=USD&to=INR";
       $data = file_get_contents($url);
         preg_match("/<span class=bld>(.*)<\/span>/",$data, $converted);
            
     $new_price = preg_replace("/[^0-9.]/", "", $converted[1]);
    

return    $new_price;
}




echo "1$==".$current_dolar_rate=current_rate(1) ." INR";
?>

Show all images as array from a folder or directory in php

<?php
$myfull_path="/uploads";
$images=array();

if ($dir = opendir( $myfull_path)) {
    $images = array();
    while (false !== ($file = readdir($dir))) {
        if ($file != "." && $file != ".." )
        {
        $ext=strtolower(getExtension($file));
       
        if ($ext=="jpg" || $ext=="jepg" || $ext=="png" || $ext=="gif" || $ext=="bmp" )   
        {

            $images[] = $file;
        }
       
        }
    }
    closedir($dir);
}



print_r($images);

function getExtension($str)
{
         $i = strrpos($str,".");
         if (!$i) { return ""; }
         $l = strlen($str) - $i;
         $ext = substr($str,$i+1,$l);
         return $ext;
}

?>

get all images as array from a folder or directory in php

<?php
$myfull_path="/uploads";
$images=array();

if ($dir = opendir( $myfull_path)) {
    $images = array();
    while (false !== ($file = readdir($dir))) {
        if ($file != "." && $file != ".." )
        {
        $ext=strtolower(getExtension($file));
       
        if ($ext=="jpg" || $ext=="jepg" || $ext=="png" || $ext=="gif" || $ext=="bmp" )   
        {

            $images[] = $file;
        }
       
        }
    }
    closedir($dir);
}



print_r($images);

function getExtension($str)
{
         $i = strrpos($str,".");
         if (!$i) { return ""; }
         $l = strlen($str) - $i;
         $ext = substr($str,$i+1,$l);
         return $ext;
}

?>

Get Dollar current rate with INR



<?php
function current_rate($price=1)
{
  
        $url  = "http://www.google.com/finance/converter?a=$price&from=USD&to=INR";
       $data = file_get_contents($url);
         preg_match("/<span class=bld>(.*)<\/span>/",$data, $converted);
            
     $new_price = preg_replace("/[^0-9.]/", "", $converted[1]);
    

return    $new_price;
}




echo "1$==".$current_dolar_rate=current_rate(1) ." INR";
?>

check a valid file extension and size in php

<?php
    $allowed_ext = array(
             'jpg'    =>    true,
            'gif'    =>    true,
            'png'    =>    true
     );




$allowed_imagesize=1024000;

    function easy_checkvalid_ext($ext,$allowed_ext)
    {
     
     
       if($allowed_ext[$ext])
        {
            return true;
        }
       else
        {
           return false;
       }  
    
       }
   
    function getExtension($str)
{
         $i = strrpos($str,".");
         if (!$i) { return ""; }
         $l = strlen($str) - $i;
         $ext = substr($str,$i+1,$l);
         return $ext;
}   
 
     


      
    function easy_checkfile_size($size,$allowed_imagesize) {
    
       if($size < $allowed_imagesize)
        {    return true;}
       
       else
        {
             return false;
    
       }
    }

       $ext=getExtension($_FILES["files"]["name"]);    
      $validfile = easy_checkvalid_ext($ext,$allowed_image_format);
      $validfilesize = easy_checkfile_size($_FILES["files"]["size"],$allowed_imagesize);

if (!$validfilesize or  !$validfile)
{
echo "not a valid file format or too big size";   
}

?>

check valid Extension in php

<?php
$allowed_ext = array(
             'jpg'    =>    true,
            'gif'    =>    true,
            'png'    =>    true
     );

    function easy_checkvalid_ext($ext,$allowed_ext)
    {
     
     if($allowed_ext[$ext])
        {
            return true;
        }
       else
        {
           return false;
       }  
    
       }

 $validfile = easy_checkvalid_ext('jpg',$allowed_image_format);

if ( !$validfile)
echo "not a valid file type";
?>

Get country code by ip address in php

<?php

function get_easy_visitor_country($ip_address)
{
    if (!$ip_address)
     $ip_address=$_SERVER['REMOTE_ADDR'];
   
     $geopluginURL='http://www.geoplugin.net/php.gp?ip='.$ip_address;
     $addrDetailsArr =@unserialize(file_get_contents($geopluginURL));
      easy_debug($addrDetailsArr);
     $result=$addrDetailsArr['geoplugin_countryCode'];
    return $result;
}


function easy_debug($obj)
{

echo "<pre>";
     print_r(  $obj);
     echo "</pre>";
 
}

?>
Freelance Jobs