Monday 22 June 2015

How To Add Taxonomy In Multiple Post In Wordpress

Hello

Some Time Same Taxonomy use in multiple post. for example onw taxonomy like music

I Want to use multiple post like WordPress default post,musician,or another post.

I have Solution for that check below code

<?php
register_taxonomy('music',array('musician','post','page'), array(
    'hierarchical' => true,
    'labels' => $labels,
    'show_ui' => true,
    'query_var' => true,
    'rewrite' => array( 'slug' => 'music' ),
  ));
?>

here  music is your taxonomy name. in your array add your post i have added post,musician,page etc

this code add to your theme in function.php or plugin file.

that can be worked

Friday 19 June 2015

Wp Query Get Child Post Or Page Of Current Page Or Post In Wordpress(Parent Post)

Hello

I am Giving example of how to get  parent post of child post or page.

I have top market post type. i am create child post in this i have code to get child post of current parent post.

  $args = array(
    'post_type'      => 'top_markets',
    'posts_per_page' => -1,
    'post_parent'    => $post->ID,
    'order'          => 'ASC',
    'orderby'        => 'menu_order'
 );


$parent = new WP_Query( $args );

if ( $parent->have_posts() ) : ?>

    <?php while ( $parent->have_posts() ) : $parent->the_post(); ?>

        <div id="parent-<?php the_ID(); ?>" class="parent-page">

            <h1><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h1>


        </div>

    <?php endwhile; ?>

<?php endif; wp_reset_query(); ?>


if you to want current page child page in wordpres check this code in your template file.

$args = array(
    'post_type'      => 'page',
    'posts_per_page' => -1,
    'post_parent'    => $post->ID,
    'order'          => 'ASC',
    'orderby'        => 'menu_order'
 );


$parent = new WP_Query( $args );

if ( $parent->have_posts() ) : ?>

    <?php while ( $parent->have_posts() ) : $parent->the_post(); ?>

        <div id="parent-<?php the_ID(); ?>" class="parent-page">

            <h1><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h1>


        </div>

    <?php endwhile; ?>

<?php endif; wp_reset_query(); ?>

Thursday 11 June 2015

Create Simple Text With Image Widget In Wordpress

Hell All,

I am have simple text widget With image. you can upload image and you can add link on
image you can add class and id on image also you can add height and width in widget.

Please Check My Widget Image you can understand that.




I am create plugin for it. in pluun in folder => create folder myWidget => create file
=>myWidget .php and same folder create js file => upload-media.js

after you can check code in file

in myWidget .php file add this code

<?php
/**
* Plugin Name: My Widget
* Plugin URI: http://myphpinformation.blogspot.in/
* Description: This plugin for widget.
* Version: 1.0.0
* Author: jaydisinh Parmar
* Author URI: http://myphpinformation.blogspot.in/
*/ 
function ctUp_wdScript(){

                wp_enqueue_script('jquery');
                wp_enqueue_script('media-upload');
                 wp_enqueue_script('thickbox');
                wp_enqueue_script('upload_media_widget', plugin_dir_url(__FILE__) . 'upload-media.js', array('jquery'));
        }
        add_action('admin_enqueue_scripts', 'ctUp_wdScript');
                function my_admin_styles() {
        wp_enqueue_style('thickbox');
        }

add_action('admin_print_styles', 'my_admin_styles');
    

?>

<?php
class My_Widget extends WP_Widget {
    
    
    function __construct() {
parent::__construct(
'my_widget', // Base ID
__( 'A Text Widget', 'text_domain' ), // Name
array( 'description' => __( 'Just Text Widget', 'text_domain' ), ) // Args
);
        
       
        
}
    
    public function widget( $args, $instance ) {
        
        echo $args['before_widget'];
        
        if ( ! empty( $instance['title'] ) ) {
echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ). $args['after_title'];
}else{
echo __( 'Hello, World! HappY', 'text_domain' );  
}
        if ( ! empty( $instance['desc'] ) ) {
echo $args['before_title'] .$instance['desc']. $args['after_title'];
}
        
        if ( ! empty( $instance['height'] ) ) {
            
            $height = $instance['height'];
            }else{
                
                $height = "300";
            }
            
            if ( ! empty( $instance['width'] ) ) {
            
            $width = $instance['width'];
            }else{
                
                $width = "300";
            }
            
            if ( ! empty( $instance['link_url'] ) ) {
            
            $link_url = $instance['link_url'];
            }
        
       
         if ( ! empty( $instance['image'] ) ) {
            echo $args['before_title'];?>
<?php if($link_url){ ?><a href="<?php echo $link_url; ?>"><?php } ?><img src="<?php echo  $instance['image']?>" height="<?php echo  $height; ?>" width="<?php echo  $width; ?>" class="<?php echo  $instance['image_class']?>" id="<?php echo  $instance['image_id']?>" /><?php if($link_url){ ?></a><?php } ?>
            <?php $args['after_title'];
}
    }
    
    
            
    
    public function form( $instance ) {
        $title = ! empty( $instance['title'] ) ? $instance['title'] : __( 'New title', 'text_domain' );
        $desc = ! empty( $instance['desc'] ) ? $instance['desc'] : '';
        $image = ! empty( $instance['image'] ) ? $instance['image'] : '';
        $link_url = ! empty( $instance['link_url'] ) ? $instance['link_url'] : '';
        $height = ! empty( $instance['height'] ) ? $instance['height'] : '';
        $width = ! empty( $instance['width'] ) ? $instance['width'] : '';
        $image_id = ! empty( $instance['image_id'] ) ? $instance['image_id'] : '';
        $image_class = ! empty( $instance['image_class'] ) ? $instance['image_class'] : '';
    ?>
    
        <p>
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label> 
<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>"/>
</p>
        
         <p>
<label for="<?php echo $this->get_field_id( 'DeScription' ); ?>"><?php _e( 'DeScription:' ); ?></label> 
<textarea class="widefat" id="<?php echo $this->get_field_id( 'desc' ); ?>" name="<?php echo $this->get_field_name( 'desc' ); ?>"><?php echo esc_attr( $desc ); ?></textarea>
</p>
        
        <p>
<label for="<?php echo $this->get_field_id( 'link_url' ); ?>"><?php _e( 'On Image Link Url:' ); ?></label> 
<input class="widefat" id="<?php echo $this->get_field_id( 'link_url' ); ?>" name="<?php echo $this->get_field_name( 'link_url' ); ?>" type="text" value="<?php echo esc_attr( $link_url ); ?>"/>
</p>
        
        <p>
<label for="<?php echo $this->get_field_id( 'height' ); ?>"><?php _e( 'Image Height:' ); ?></label> 
<input class="widefat" id="<?php echo $this->get_field_id( 'height' ); ?>" name="<?php echo $this->get_field_name( 'height' ); ?>" type="text" value="<?php echo esc_attr( $height ); ?>"/>
</p>
        
        <p>
<label for="<?php echo $this->get_field_id( 'width' ); ?>"><?php _e( 'Image Width:' ); ?></label> 
<input class="widefat" id="<?php echo $this->get_field_id( 'width' ); ?>" name="<?php echo $this->get_field_name( 'width' ); ?>" type="text" value="<?php echo esc_attr( $width ); ?>"/>
</p>
        
        <p>
<label for="<?php echo $this->get_field_id( 'image_id' ); ?>"><?php _e( 'Image ID:' ); ?></label> 
<input class="widefat" id="<?php echo $this->get_field_id( 'image_id' ); ?>" name="<?php echo $this->get_field_name( 'image_id' ); ?>" type="text" value="<?php echo esc_attr( $image_id ); ?>"/>
</p>
        
         <p>
<label for="<?php echo $this->get_field_id( 'image_class' ); ?>"><?php _e( 'Image Calss:' ); ?></label> 
<input class="widefat" id="<?php echo $this->get_field_id( 'image_class' ); ?>" name="<?php echo $this->get_field_name( 'image_class' ); ?>" type="text" value="<?php echo esc_attr( $image_id ); ?>"/>
</p>
        
        <p>
           <input name="image" class="my_upload_image_button" type="button" value="Upload"/>
           <input class="widefat upload_image" id="<?php echo $this->get_field_id( 'image' ); ?>" name="<?php echo $this->get_field_name( 'image' ); ?>" type="text" value="<?php echo esc_attr( $image ); ?>" readonly=""/>
           <?php if(!empty($image)){ ?>
           <img src="<?php echo esc_attr( $image ); ?>" height="100" width="100" />
           <?php } ?>
        </p>
    
        
<?php 
        
        }
        
        public function update( $new_instance, $old_instance ) {
$instance = array();
$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
        $instance['desc'] = ( ! empty( $new_instance['desc'] ) ) ? ( $new_instance['desc'] ) : '';
        $instance['image'] = ( ! empty( $new_instance['image'] ) ) ? ( $new_instance['image'] ) : '';
        $instance['link_url'] = ( ! empty( $new_instance['link_url'] ) ) ? ( $new_instance['link_url'] ) : '';
        $instance['height'] = ( ! empty( $new_instance['height'] ) ) ? ( $new_instance['height'] ) : '';
        $instance['width'] = ( ! empty( $new_instance['width'] ) ) ? ( $new_instance['width'] ) : '';
        $instance['image_id'] = ( ! empty( $new_instance['image_id'] ) ) ? ( $new_instance['image_id'] ) : '';
        $instance['image_class'] = ( ! empty( $new_instance['image_class'] ) ) ? ( $new_instance['image_class'] ) : '';

return $instance;
}

    
}

add_action( 'widgets_init', function(){
     register_widget( 'My_Widget' );
});

?>

after in your upload-media.js file add this code

jQuery(document).ready(function($) {
  $(document).on("click", ".my_upload_image_button", function() { 

window.send_to_editor = function(html) {
imgurl = jQuery('img',html).attr('src');
$('.upload_image').val(imgurl);

        tb_remove();
};

tb_show('', 'media-upload.php?type=image&TB_iframe=true');
return false;
  });
});

after this active plugin in My Widget. go to Appearance and check the in widgets => check
A Text Widget add in sidebar.




Tuesday 9 June 2015

Implode And Explode Function In Php

Hello All,

Here I Want give example of how to use implode and explode in php.

Use of Implode 


=> The implode() function returns a string from the elements of an array. separator parameter of implode() is optional.

I give example for it.


$array = array("hello","all","be","happy","always");

$result =  implode($array);

echo $result;

it result will be => helloallbehappyalways.

if you can separate array using space then you can write this way

 $result =  implode(" ",$array);

this result will me => hello all be happy always

you can any of parameter to separate array;

like i give emaple for it


echo $result =  implode("$",$array)."<br/>";
echo $result =  implode("+",$array)."<br/>";
echo $result =  implode("-",$array)."<br/>";
echo  $result =  implode("*",$array)."<br/>";

this result will me =>

hello$all$be$happy$always
hello+all+be+happy+always
hello-all-be-happy-always
hello*all*be*happy*always

I think yon can understand what implode work it can make string of array using separate
by it parameter.you can use different parameter that can separate it. 

Use of Explode

=> this function use of breaks a string into an array.separator parameter cannot be empty string.

i will give example for it.

$string = "Lorem Ipsum is simply dummy text of the printing and typesetting industry";
$result = explode(" ",$string);
print_r($result);

this result will be=>
Array ( [0] => Lorem [1] => Ipsum [2] => is [3] => simply [4] => dummy [5] => text [6] => of [7] => the [8] => printing [9] => and [10] => typesetting [11] => industry )

if you want to separate to this different word.

if you to get separate word then check below code

echo "<br/>";
 $count = count($result);
 
 for($i=1;$i<=$count;$i++){
    
    $line =  each($result);
    print_r($line);
    echo "<br/>";
    echo $line['value']."<br/>";
 }

this out put will be
=>
Lorem
Array ( [1] => Ipsum [value] => Ipsum [0] => 1 [key] => 1 )
Ipsum
Array ( [1] => is [value] => is [0] => 2 [key] => 2 )
is
Array ( [1] => simply [value] => simply [0] => 3 [key] => 3 )
simply
Array ( [1] => dummy [value] => dummy [0] => 4 [key] => 4 )
dummy
Array ( [1] => text [value] => text [0] => 5 [key] => 5 )
text
Array ( [1] => of [value] => of [0] => 6 [key] => 6 )
of
Array ( [1] => the [value] => the [0] => 7 [key] => 7 )
the
Array ( [1] => printing [value] => printing [0] => 8 [key] => 8 )
printing
Array ( [1] => and [value] => and [0] => 9 [key] => 9 )
and
Array ( [1] => typesetting [value] => typesetting [0] => 10 [key] => 10 )
typesetting
Array ( [1] => industry [value] => industry [0] => 11 [key] => 11 )
industry

if you want to get only word echo $line['value]; use it and print_r($line); comment it.

you can also limit parameter to return a number of array elements

check this example

$string = "Lorem,Ipsum,is,simply,dummy,text,of,the,printing,and,typesetting,industry";

if you want to only 1 key then code this

print_r(explode(',',$string,0));

this result will =>
Array ( [0] => Lorem,Ipsum,is,simply,dummy,text,of,the,printing,and,typesetting,industry )

if you want 2 key then

print_r(explode(',',$string,2));

this result will=>
Array ( [0] => Lorem [1] => Ipsum,is,simply,dummy,text,of,the,printing,and,typesetting,industry )

if you want all key then you can use this code

print_r(explode(',',$string,-1));


this result will be =>

Array ( [0] => Lorem [1] => Ipsum [2] => is [3] => simply [4] => dummy [5] => text [6] => of [7] => the [8] => printing [9] => and [10] => typesetting )

this use of explode and implode. explode use for string to array and implode use for array to string.

 



 

Email Already Exit Using Jquery And Php

Hello All,

I am Simple Learn How to check email already exit. I am create code and check if

email already exit then you cannot submit  and also also validation of email.

I am give the code for that you can check it and use it.

you have to create to file

1)email.php
2)check.php

in your email.php wriite this code

<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
 
   $("#myform").submit(function(){
 
       if(!emailok)
       {
        alert('check your email');
        return false;
       }
   
    });
$('#email').blur(function(){
   alert($('#email').val());
    $.ajax({
        type:"post",
        data:"email="+$('#email').val(),
        url:"check.php",
        beforeSend:function(){
            $("#email_info").html("checking email...");
        },
        success:function(data){
         
            if(data == "invalid"){
                $("#email_info").html("check your Email");
           
       
            emailok = false;
            }else if(data !="0"){
                  $("#email_info").html("email already exit");
             
            }else{
            emailok = true;
            $("#email_info").html("email ok");
            }
         
         
        }
     
     
     
    });
 
    });
});
</script>
<form id="myform" method="post">
<input type="text" id="email" name="email"/>
<input type="submit" />
</form>
<div id="email_info"></div>


second file is check.php

add this code

<?php
 $dbhost = 'localhost';
   $dbuser = 'root';
   $dbpass = '';
   $conn = mysql_connect($dbhost, $dbuser, $dbpass);
   if(! $conn )
   {
     die('Could not connect: ' . mysql_error());
   }

 
   mysql_select_db('blog',$conn);
 
   $email = $_POST['email'];
 
   if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
 
   $sql =  mysql_query('select email from email where email="'.$email.'"' );
 
   $result = mysql_fetch_array($sql);
 
 
 
    echo $num = mysql_num_rows($sql);
 }else{
 
    echo "invalid";
 }
 
 
 
 
 
 
   mysql_close($conn);
?>

table code

--
-- Table structure for table `email`
--

CREATE TABLE IF NOT EXISTS `email` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `email` varchar(200) NOT NULL,
  `password` varchar(200) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;

--
-- Dumping data for table `email`
--

INSERT INTO `email` (`id`, `email`, `password`) VALUES
(1, 'test@gmail.com', 'test'),
(2, 'teset@gmail.com', 'test');

Friday 5 June 2015

Convert String To Title Case With Jquery And Title Case Microsoft Office

Hello All,


This My learn how to change title case using jquery. I am also Learn that how to
change title case in MsOffice.

When I have Text  TO HAVE A CLEAR AND FOCUSSED CONTENT  in MsOfiice
I am want to change it into To Have A Clear And Focussed Content. I have no Idea 
about that. I am also don't what to say in MsOffice that's I want to make code in jquery.

I have change manually but  I thought if I have many of text that I do code. I also Find instruction

in Msoffice.

It That


  1. Select the text you want to alter.
  2. Press Shift+F3. Word changes the case of the selected text.
  3. Continue pressing Shift+F3 until the case is the way you want it.

When First i select text TO HAVE A CLEAR AND FOCUSSED CONTENT and press shift+f3
it make it Small. after again press Shift+f3. Then Get this text To Have A Clear And Focussed Content.

So I think When Get code Also using Jquery then  I Will Put here and try some one
who can khow developing.



<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    
    var text = $('.capitalize').text();
    
    var ti = toTitleCase(text);

      $('.capitalize').empty();
      $('.capitalize').append(ti);
    function toTitleCase(str)
{
    return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
}

});
</script>
<div class='capitalize'>
    TO HAVE A CLEAR AND FOCUSSED CONTENT
</div>

in div you can put your text and check in your browser you can get output.



Tuesday 2 June 2015

Create Child Theme Of Wordpress Theme And Create Template In Wordpress

Hello All,

Here Simple Create Child theme in wordpss and how to create template in Wordpress.
Here I see the example of make child theme twentythirteen. same step use you can
create any of theme child theme.

Use Of child theme.

Child theme very usefull. because some time theme have update. we can update it theme
then you can change stucture is removed. but you can make child theme can be usefull.

Simple Follow Step you can create child theme in wordpress Easily.

Step:1 
First Goto Wordpress Theme Folder.=>/wp-content/themes/
Then Create child Theme Like I am Create thirteenchild Folder.

Step:2
Here Simple create style.css and add the below code.

/*
Theme Name:     twentythirteenchild
Theme URI:      http://myphpinformation.blogspot.in
Author:         coder
Author URI:     http://myphpinformation.blogspot.in
Template:       twentythirteen
Version:        0.1
*/


@import url("../twentythirteen/style.css");

Step:3
After login your dashboard (wordpress Admin) 
Go To :=> Appearance > Themes
and active your theme child theme. here theme name is twentythirteenchild.

Second How to create template in wordpress.

Step1:-
you want to create template. you just copy page.php file or create new page 

if you want to create page template it's better to copy page.php file. 

Step2 : 

page.php ot new page add below code in header.

<?php /* Template Name: My Custom Page */ ?>

check it wp-admin page=>edit or new page you can see On the right hand side under attributes you’ll see template.