wordpress_add

Saturday 28 December 2013

Image resizing using Php

The following Code will easily allow you to resize images using PHP.
Awesome and simple method to resize image.while uploading new image. dr-wordpress


Copy and paste ( just run this code and check the flow of code.)


This is just a php function that passes the source image ( i.e., $source_img ), destination image ( $destination_img ) and quality for the image that will take to compress ( i.e., 90 ).
$filename = compress_image($_FILES["file"]["tmp_name"], $url, 80);
"80" is the quality of image (1-99) dr-wordpress
<---------------------------------------------------------------------------------------------------->
<?php
$name = ''; $type = ''; $size = ''; $error = '';
function compress_image($source_url, $destination_url, $quality) {

$info = getimagesize($source_url);

    if ($info['mime'] == 'image/jpeg')
        $image = imagecreatefromjpeg($source_url);

    elseif ($info['mime'] == 'image/gif')
        $image = imagecreatefromgif($source_url);

    elseif ($info['mime'] == 'image/png')
        $image = imagecreatefrompng($source_url);

    imagejpeg($image, $destination_url, $quality);
return $destination_url;
}

if ($_POST) {

    if ($_FILES["file"]["error"] > 0) {
        $error = $_FILES["file"]["error"];
   
    else if (($_FILES["file"]["type"] == "image/gif") || 
($_FILES["file"]["type"] == "image/jpeg") || 
($_FILES["file"]["type"] == "image/png") || 
($_FILES["file"]["type"] == "image/pjpeg")) {

        $url = 'destination .jpg';

        $filename = compress_image($_FILES["file"]["tmp_name"], $url, 80);
        $buffer = file_get_contents($url);

        /* Force download dialog... */
        header("Content-Type: application/force-download");
        header("Content-Type: application/octet-stream");
        header("Content-Type: application/download");

/* Don't allow caching... */
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");

        /* Set data type, size and filename */
        header("Content-Type: application/octet-stream");
        header("Content-Transfer-Encoding: binary");
        header("Content-Length: " . strlen($buffer));
        header("Content-Disposition: attachment; filename=$url");

        /* Send our file... */
        echo $buffer;
    }else {
        $error = "Uploaded image should be jpg or gif or png";
    }
}
?>
<html>
    <head>
        <title>Php code compress the image</title>
    </head>
    <body>

<div class="message">
                    <?php
                    if($_POST){
                        if ($error) {
                            ?>
                            <label class="error"><?php echo $error; ?></label>
                        <?php
                            }
                        }
                    ?>
                </div>
<fieldset class="well">
                <legend>Upload Image:</legend>                
<form action="" name="myform" id="myform" method="post" enctype="multipart/form-data">
<ul>
            <li>
<label>Upload:</label>
                               <input type="file" name="file" id="file"/>
</li>
<li>
<input type="submit" name="submit" id="submit" class="submit btn-success"/>
</li>
</ul>
</form>
</fieldset>
</body>
</html>


Subscribe Dr-Wordpress for Important Knowledge of wordpress..your's suggestions are most welcomed.

Friday 20 December 2013

Button styling using css.

Submit button style using css. dr-wordpress

Time saving practice just copy and paste this code all the input button got same styling.
I don't like the default button style.

input[type=submit]
{
width: 60px;
margin: 0;
margin-left: 8px;
border: 0;
border-radius: 2px;
-moz-border-radius: 2px;
background: #000;
background: rgba(0,0,0,.6);
color: #fff;
cursor: pointer;
font-size: 13px;
height: 26px;
z-index: 0;
}

Subscribe Dr-Wordpress for Important Knowledge of wordpress..your's suggestions are most welcomed.

Tuesday 19 November 2013

Count files in any directory using php..!!

Dr-Wordpress : how to count the number of files in any directory using php.


<?php 
    //Counts starts at 0
    $i = 0; 
    $dir = 'images/Trip_images/';
    if ($handle = opendir($dir)) {
        while (($file = readdir($handle)) !== false){
            if (!in_array($file, array('.', '..')) && !is_dir($dir.$file)) 
                $i++;
        }
    }
    // print count files in directory
    echo "There were $i files";
?>


Subscribe Dr-Wordpress for Important Knowledge of wordpress..your's suggestions are most welcomed.

Friday 15 November 2013

How to Display Child Category name and link in Wordpress.

One line code for displaying child category with relevant link. Dr-Wordpress
 DISPLAY CHILD CATEGORY IN WORDPRESS....!!! (dr-wordpress)

NOTE : "3" IS THE ID OF PARENT CATEGORY

<?php wp_list_categories('orderby=id&show_count=1&use_desc_for_title=0&child_of=3'); ?>

Subscribe Dr-Wordpress for Important Knowledge of wordpress..your's suggestions are most welcomed.

Tuesday 12 November 2013

MySQL Update Query In php..!!!

Dr-Wordpress : easy way to use update query in MySQL ( php )....!!!

<?php
ob_start();

 $db_name = 'database_name';
  $db_user = 'root';
  $db_pass = '';
 $db_host = 'localhost';
 $connection = mysql_connect($db_host, $db_user, $db_pass);
  mysql_select_db($db_name);

 ?>


$sql = "UPDATE $tablename  SET $column_name = '$value' WHERE Id='$id'";

   mysql_query($sql) or die(mysql_error());


Subscribe Dr-Wordpress for Important Knowledge of wordpress..your's suggestions are most welcomed.

How to get the value of radio button.!!!

Dr-Wordpress : through Php How to get the value of radio button...!!!

<form name="my form" method="POST" action="validate.php"> 
<label >
  <input type="radio" id="id_radio1" name="name_radio" value="1"/>Dr-wordpress 1</label>
<label>
    <input type="radio" id="id_radio2" name="name_radio" value="2"/>Dr-wordpress 2</label>
<label>
     <input type="radio" id="id_radio3" name="name_radio" value="3"/>Dr-wordpress 3</label>

<input type="submit">

</form>

NOTE : Must gave the value in input tag other wise just ON/OFF will display 

<?php

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

{
    echo $radio_value1 = $_POST["name_radio"];
}
?>


Subscribe Dr-Wordpress for Important Knowledge of wordpress..your's suggestions are most welcomed.

Friday 8 November 2013

jquery show/hide Effect with radio button...!!!

Jquery show/hide Effect with radio button

In dr-wordpress Today i going to share an important example of jquery.
I am Also badly stuck, when i am doing this.
So i am sharing this code with you people..
<!-----------------------------------------------HTML CODE------------------------------------>
<form>
<input id="id_radio1" type="radio" name="name_radio" value="value_radio1" checked="checked"/>Radio1

<input id="id_radio2" type="radio" name="name_radio" value="value_radio2" />Radio2

<input id="id_radio3" type="radio" name="name_radio" value="value_radio3" />Radio3
                 
</form>
              <div id="divs">
                   <div id="div1">One</div>
                   <div id="div2">Two</div>
                   <div id="div3">Three</div>     

              </div>
<!-----------------------------------------------CSS CODE----------------------------------------->
#divs div {
    display:none;

}
<!-----------------------------------------------Jquery CODE-------------------------------------->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>
 $(function() {
          var $divs = $('#divs > div');
          $divs.first().show()
          $('input[type=radio]').on('change',function() {
                  $divs.hide();
                  $divs.eq( $('input[type=radio]').index( this ) ).show();
           });

});
<script>


Subscribe Dr-Wordpress for Important Knowledge of wordpress..your's suggestions are most welcomed.

Thursday 7 November 2013

DR-WORDPRESS : How to make responsive design through media query.

At different resolution some time we need different style ( css ) for a particular div or span etc so we use media query for it.


NOTE: 980px means That less than 980px resolution   this is style is active.

 @media screen and (max-width: 980px) {

#header .inner 
{
    float: left;
    padding-left: 0px;
    width: 475px;
}

 }


Subscribe Dr-Wordpress for Important Knowledge of wordpress..your's suggestions are most welcomed.

Tuesday 29 October 2013

Convert image into gradient color..!!! Dr-wordpress

Here is the URL of website which convert image into gradient color and gave code to user to use it on any website etc... Dr-wordpress
Wordpress Solutions Steps :

http://gradientfinder.com/

Uplaod your image 
And than it will auto generate the code of that image 


Subscribe Dr-Wordpress for Important Knowledge of wordpress..your's suggestions are most welcomed.



Monday 14 October 2013

One Line Code for Hiding "Search here" in any Text Feild..!!!

Dr-wordpress: Put this code in input tag and call the method of onBlur..


onblur="if(this.value.length == 0) this.value='Search';" onclick="if(this.value == 'Search') this.value='';"


Subscribe Dr-Wordpress for Important Knowledge of wordpress..your's suggestions are most welcomed.

Friday 11 October 2013

Easy Method to Check browser In PHP...!!!

Here is the code to check the browser Either it is internet explorer or some other browser. 


<?php

$user_agent = $_SERVER['HTTP_USER_AGENT']; 

if (preg_match('/MSIE/i', $user_agent)) { 
   echo "Internet Explorer";   // HERE you can set any condition which you only execute in IE case
} else {
   echo "Non-IE Browser";


?>


Subscribe Dr-Wordpress for Important Knowledge of word press..your's suggestions are most welcomed.

Friday 4 October 2013

Social Icon In PHP (sharing and like buttons)

Here is the link where you got the code of sharing buttons


http://www.like-button.net/

http://www.sharethis.com/

http://www.addthis.com/


http://zocialbar.com/

************************************************************************



Subscribe Dr-Wordpress for Important Knowledge of word press..your's suggestions are most welcomed.

Wednesday 2 October 2013

IE hack ( Internet explorer HAck)

This is the Hack for internet explorer 
these lines are only executed when we use internet explorer



  • IE8 or below: to write CSS rules specificially to IE8 or below, add a backslash and 9 (\9) at the end before the semicolon.
  • IE7 or below: add an asterisk (*) before the CSS property.
  • IE6: add an underscore (_) before the property.

body {  
 color: red; /* all browsers, of course */  
 color : green\9;    /* IE8 and below */  
 *color : yellow;   /* IE7 and below */  
 _color : orange;   /* IE6 */  
}

#div { height: 300px\9; }


Subscribe Dr-Wordpress for Important Knowledge of wordpress..your's suggestions are most welcomed.

Wednesday 18 September 2013

With out using Widgets How to get recent post in any page Of WordPress..!!!

Dr-wordpress :This is the method to show the most recent post at any web page of wordpress.

Just paste this code to that File where you want to display the recent POST, Use and enjoy...:).

<?php

     $args = array(
    'numberposts' => 10,
    'offset' => 0,
    'category' => 0,
    'orderby' => 'post_date',
    'order' => 'DESC',
    'include' => ,
    'exclude' => ,
    'meta_key' => ,
    'meta_value' =>,
    'post_type' => 'post',
    'post_status' => 'draft, publish, future, pending, private',
    'suppress_filters' => true );

    $recent_posts = wp_get_recent_posts( $args, $output = ARRAY_A );
?>
 foreach( $recent_posts as $recent ){
  echo '<li><a href="' . get_permalink($recent["ID"]) . '" title="Look '.esc_attr($recent["post_title"]).'" >' .   $recent["post_title"].'</a> </li> ';
 }

Subscribe Dr-Wordpress for Important Knowledge of wordpress..your's suggestions are most welcomed.

How to style the sub menu in word press Complete code..!!! Dr-wordpress

Here is the exact code to style you sub menu in wordpress.
Before using It just keep in mind the few things.
Note : .menu is the main menu.
           ( you can change it according to your design )

After It Just paste these line to your style Sheet. Than your menu is completely styled Just Change the color and effects according to you web design.. 

.menu
{
width:660px;
height:30px;
float:left;
margin-left:4px;
margin-top:30px;
}



.menu ul, .menu li {
    list-style: none outside none;
    margin: 0;
    padding: 0;
}
.menu li {
  /*  background-image: url("images/sep.gif");*/
    background-position: 0 15px;
    background-repeat: no-repeat;
    float: left;
    margin-left: 5px;
    margin-top: 2px;
    padding-left: 9px;
    position: relative;
}
.menu li.first {
    background-image: none;
    padding-left: 0;
}
.menu li a {
    color: #FFFFFF;
    display: block;
    padding: 8px 5px;
    text-decoration: none;
}
.menu li a:hover {
    color: #A59B00;
    text-decoration: none;
}
.menu ul {
    margin-left: 26px;
    margin-top: 43px;
}
.menu ul ul {
    display: none;
    float: left;
    left: 0;
    margin: 0;
    position: absolute;
    top: 34px;
    width: 150px;
    z-index: 200;
}
.menu ul ul li {
    background: none repeat scroll 0 0 transparent;
    border-bottom: 1px solid #716A00;
    float: none;
    height: auto;
    margin: 0;
    min-width: 120px;
    padding: 0;
}
.menu ul ul li a {
    background-color: #B7AF34;
    color: #FFFFFF;
    display: block;
    height: auto;
    line-height: 1em;
    padding: 5px 10px;
    text-decoration: none;
}
.menu ul ul li a:hover {
    background-color: #D2CA55;
    color: #FFFFFF;
}
.menu ul ul ul {
    left: 100%;
    top: 0;
}
.menu ul li:hover > ul {
    display: block;
}
.menu ul li.current_page_item > a, .menu ul li.current_page_ancestor > a, .menu ul li.current_menu_item > a, .menu ul li.current_page_parent > a {
    color: #A59B00;
}


Subscribe Dr-Wordpress for Important Knowledge of wordpress..your's suggestions are most welcomed.




Tuesday 17 September 2013

How to Show Post in "Random Order " using Wordpress..!!!


Dr-wordpress : Today i am going to share a method of showing random POST in any word press page..just like QUIZ example or Captacha.You can also use it on different places where you want to show random POST's in wordpress...



wp_reset_query();

   query_posts("post_type=blog&posts_per_page=1&orderby=rand");
 
      while ( have_posts() ) : the_post();
$post_thumbnail_id = get_post_thumbnail_id( get_the_id() ); 
 $url=wp_get_attachment_image_src(  $post_thumbnail_id,"medium" );
?>

     <h1><?php the_title() ?></h1>



Subscribe us for Important Knowledge of wordpress ..your's suggestions are most welcomed.

Using "SLUG" how to get post and page content..!!!

SLUG are used in WordPress ( permalinks structure. ).Basically it is a unique name auto generated by word press. You can also change it...You get specific POST and page content by using slug.It is always in small letters with "-".

For example:

www.abc.com/slug-test

Here is the method to get Slug

<?php 
$slug = get_post( $post )->post_name;
echo $slug; 
?>

Now you have unique name use it and get the specific post and page content by using manual method of POST.


Subscribe Dr-Wordpress for Important Knowledge of wordpress..your's suggestions are most welcomed.

Monday 16 September 2013

How to add "READ MORE" tag in wordpress Post..??

This the method to To add you "READ MORE" option in word press post or page..

NOTE: (243 is the dummy id)

$post_id2 = 243;
$queried_post2 = get_post($post_id2);
$title2 = $queried_post2->post_title;
echo substr($queried_post2->post_content,0,243);


Subscribe Dr-Wordpress for Important Knowledge of word press..your's suggestions are most welcomed.

How to get current URL at any page..??

This is the method to get URL of current page.Use and enjoy 

$link2=$_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] ;

$link_n2=explode('myvar',$link2);


echo $link_n2[1];




Subscribe Dr-Wordpress for Important Knowledge of word press..your's suggestions are most welcomed.


Get page content_in_tempalte..?

This is the method to get content on any template from WordPress edit panel.

<?php 
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> 
         <?php the_content(); ?>
     <?php endwhile; ?>  
   <?php 
endif; ?>


Subscribe Dr-Wordpress for Important Knowledge of word press..your's suggestions are most welcomed.

Friday 13 September 2013

How to sort Alphabetically in word press..??

 Here is the procedure to sort alphabetically in word press.


$args = array( 'post_type' => 'instructors', 'orderby'=>'title','order'=>'ASC' );


for custom fields:

$args = array( 'post_type' => 'calendar' , 'posts_per_page'    => '-1' ,'meta_key'=>'course_name','orderby' => 'meta_value', 'order' => 'ASC' );

Suggestions are welcomed..


Subscribe Dr-Wordpress for Important Knowledge of word press..your's suggestions are most welcomed.

Thursday 12 September 2013

Check online That your website is responsive or Not...???

To check that your site is responsive or not visit this link

This is the link,You just paste you URL and check the responsive layout of your website.

http://mattkersley.com/responsive/


Subscribe us for Important Knowledge of word press..your's suggestions are most welcomed..

Tuesday 10 September 2013

How to get Site URL..?

This is the method to get site URL for example ( www.abc.com/ )
main purpose behind this when you want to add some image or want to fetch some data from server which is present on some Folder than you put this code before that folder.

TO link the logo with main site link we use:
<?php echo get_site_url(); ?>

 Gave directory path of active theme
<?php echo get_bloginfo('template_url'); ?>/ FOLDER-NAME

 

Subscribe us for Important Knowledge of word press.Your's suggestions are most welcomed..

Monday 9 September 2013

How to make template in word press..??

This is the Php code for make template In word press.

<?php
/*
Template Name:Price Page
 */

After it you may give it your look as you needed..


get_header();   // It is used for get the header file in template just like include in php
get_footer();   // It is used for get the footer file in template just like include in php..

( Note: remember these function enclosed within php tags.)


Subscribe us for Important Knowledge of word press.Your's suggestions are most welcomed..


To allign the content in ( internet Explorer) IE.....

To align the Webpage in IE use these lines for alignment.

<style type="text/css">
body{text-align: center}
div{text-align: left; width: 50em; margin:0 auto; border:1px solid #CCCCCC}
</style>


Subscribe us for Important Knowledge of word press.Your's suggestions are most welcomed..

HOw to Add custom menu in word press..

Locate Function.php and paste this code in it.


function register_my_menus() {
register_nav_menus(
array(
'left-menu' => __( 'Left Menu' ),
'home-menu' => __( 'Home Menu' )
)
);
}
add_action( 'init', 'register_my_menus' );


//Paste this code on any page or template...



 <?php wp_nav_menu( array( 'theme_location' => 'left-menu' )); ?>


Here is the code for default menu.Remember don't do styling of <ul>  Make a <div> outside to it and style that div.

example: .div ul {   }

 <?php wp_nav_menu( array( 'theme_location' => 'primary' )); ?>



Subscribe us for Important Knowledge of word press.Your's suggestions are most welcomed..

Custom widget Area In wordpress

Locate functions.php in your active theme folder and add the bellow code in it.


if ( function_exists('register_sidebar') )

    register_sidebar(array(


        'name' => 'recent posts',


'id'=>'recent',


        'before_widget' => '',


        'after_widget' => '',


        'before_title' => '',


        'after_title' => '',


    ));



if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('recent') ) : ?>


     <p>This is what shows when no widgets are added.</p>      


<?php 
endif; ?>



Subscribe us for Important Knowledge of word press.Your's suggestions are most welcomed..


Friday 6 September 2013

Custom Post type and custom feild in wordpress....

Today We Going to explain the important task that to add custom post in WordPress( including images,files,text etc )


First of all download this plugin

" Simple Custom post type custom field"

Than Add the custom feild where you want to add in your wordpress site.
here is the code to use this plugin on your page.


<?php $data = simple_cck::get_post_data($my_id); //print_r($data);?>

 src="<?php print_r($data['img1']['image_data'][0]); ?>"


<a href="<?php print_r($data['summary']['file']);?>">Click to View</a>



Subscribe us for Important Knowledge of word press.Your's suggestions are most welcomed..

FOR GETTING POST IN ANY WEB PAGE

This is the method to get the selective post (  $post_id = 26; 26 is the id it may be change )

Method 1 <?php
$post_id = 26;
$queried_post = get_post($post_id);
$title = $queried_post->post_title;
echo $title;
echo $queried_post->post_content;
?>



Method 2

<?php // retrieve one post with an ID of 1
query_posts('p=1'); ?>
<?php while (have_posts()) : the_post(); ?>
<h4><?php the_title(); ?></h4>
<?php the_content(); ?>
<?php endwhile;?>

Subscribe us for Important Knowledge of word press.Your's suggestions are most welcomed..

HOW TO GET FEATURED IMAGE IN WORDPRESS

This is the way to get featured image in wordpress..
just paste this code where you want to get featured image in wordpress..


<?php  $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' );?>
<img src="<?php echo $image[0]; ?>" />


Subscribe Dr-Wordpress for Important Knowledge of wordpress..your's suggestions are most welcomed.

Thursday 5 September 2013

FQA. when i insert an image from a url..??

When image is inserted From external server.

It doesn't download that image just use the external link.
So image should available only if it is present on that link or server.


Subscribe us for Important Knowledge of word press.Your's suggestions are most welcomed..



How to get the POST of CATEGORY in wordpress

This is the method to get all the post of Respective Category in wordpress.

NOTE : ( cat="1"  is the ID of that category in which post exist It may be change .)


<?php
query_posts('cat=1');
while (have_posts()) : the_post();
the_content();
endwhile;
?>



Subscribe Dr-Wordpress for Important Knowledge of word press..your's suggestions are most welcomed.




How to get theme Directory.?

FOR GETTING DIRECTORIES ( LIKE  PATH OF IMAGES )

<?php echo get_bloginfo('template_url'); ?> 

Example:

<img src="<?php echo get_bloginfo('template_url'); ?> /A.jpg" />


Subscribe us for Important Knowledge of word press.Your's suggestions are most welcomed..