how to make shortcode of custome field type in wordpress

1. Copy this php script in your functions.php
function field_scode($value){
global $post;
$name = $value['name'];
if(empty($name)) return;
return get_post_meta($post->ID,$name,true);
}
add_shortcode('my_shortcode','field_scode');

/* use this shortcode in your post or page or in template
exp:- [my_shortcode  name="put_field_name_here"]
*/

Php script for file download

1. PHP Script for image download you can make any file to to download Paste this script in your file or save it download.php
<?php
$imageurl = filter_input(INPUT_GET, 'imageurl', FILTER_SANITIZE_URL);
// Clean the image URL to get the path and make sure the user is just getting an image.
$url_parsed = parse_url($imageurl);
$file = $_SERVER['DOCUMENT_ROOT'] .'/base-directory'. $url_parsed['path'];
print_r($file);
// Get the extension of the file.
$extension = substr(strrchr($file ,'.'), 1);

// Limit the extensions in this array to those you're allowing the user to download.

$allowed_extensions = array('jpg', 'jpeg', 'png', 'gif');

// Make sure the file requested is in your list of allowed extensions to make sure the user isn't downloading something other than an image.

if (in_array(strtolower($extension), $allowed_extensions)) {

    if (file_exists($file)) {

        header ('Content-type: octet/stream');

        header ('Content-disposition: attachment; filename=' . basename($file) . ';');

        header('Content-Length: ' . filesize($file));

         ob_clean();
        readfile($file);
    }
}
?>
1. HTML Code Paste this code in your html file

    Download  
	
Enjoy......

How to show costum sidebar in wordpress template

<?php

/**

 * Template Name: Home Page Template

 */

get_header(); ?>


Make plugin using shortcode in wordpress to display database information

<?php
/**

 * Plugin Name:user info

 * Plugin URI: http://wordpress_aprai.org

 * Description: this plugin will be display data from database you can use this shortcode any where

 * Author:Arunendra Pratap rai

 */


 function display()

 {

global $wpdb;

$sql ="select * from `first_projectposts` where `post_type` = 'DisplayPost'";

$query = $wpdb->get_results($sql);

echo '';

foreach($query as $data){

$id = $data->ID;   $fname=$data->post_title;       $lname=$data->post_status;    $email=$data->post_type;  $pass=$data->post_name;

echo '';

}

echo '
idfirst nameLast nameemail idPassword
'.$id.''.$fname.''.$lname.''.$email.''.$pass.'
'; } add_shortcode( 'short_code', 'display' ); // you can use any unique name for short code ?>
USAGE :- in post or page use :-
[short_code] In template use:-
<?php echo do_shortcode('[short_code]') ?>

Wordpress install and uninstall plugin table during activation and deactivation of plugin

<?php
/*

Plugin Name: sample plugin

Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates

Description: This plugin is used to add youtube embeded video code and show video in widgets.

Version: 2.1

Author: Arunendra Pratap Rai

Author URI: http://URI_Of_The_Plugin_Author

License: A "Slug" license name e.g. GPL2

*/

register_activation_hook(__FILE__,'pro_install'); // table installation hook

register_deactivation_hook(__FILE__ , 'pro_uninstall' ); //table uninstallation hook

function pro_install()

{

    global $wpdb;

    $table = wp_."table_name";

    $structure = "CREATE TABLE $table (

        id INT(9) NOT NULL AUTO_INCREMENT,

        fname VARCHAR(255) NOT NULL,

        lname VARCHAR(255) NOT NULL,

      


    UNIQUE KEY id (id)

    );";

    $wpdb->query($structure);

      // Populate table

    $wpdb->query("INSERT INTO $table(id,fname,lname)

        VALUES('1', 'arunendra','Pratap rai')");


}

function pro_uninstall()

{

    global $wpdb;

    $table = wp_."table_name";

    $structure = "drop table if exists $table";

    $wpdb->query($structure); 

}
?>