wordpress_add

Showing posts with label php. Show all posts
Showing posts with label php. Show all posts

Thursday, 30 January 2014

Pagination in wordpress

Pagination in wordpress

First of all download this plugin

https://codex.wordpress.org/Pagination

than paste this code in any template where you want to show all the posts


<?php 


// the query to set the posts per page to 3

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array('posts_per_page' => 3, 'paged' => $paged );
query_posts($args); ?>
<!-- the loop -->
<?php if ( have_posts() ) : while (have_posts()) : the_post(); ?>
  <!-- rest of the loop -->
  <!-- the title, the content etc.. -->
<?php endwhile; ?>
<!-- pagination -->
<?php next_posts_link(); ?>
<?php previous_posts_link(); ?>
<?php else : ?>
<!-- No posts found -->
<?php endif; ?>


if you want to show the post of specific category than replace this code in above code at line 2. 

$args = array('cat' => '7','posts_per_page' => 3, 'paged' => $paged );

NOTE : cat=>7 will be any Number ( ID of specific category)

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


Thursday, 23 January 2014

Wordpress Search in Dr-wordpress

Wordpress Search : ( dr-wordpress.blogspot.com)

<form role="search" method="get" id="searchform" action="<?php echo home_url( '/' ); ?>">
    <div>
        <input type="text" value="" name="s" id="s" placeholder="Search Here..." />
        <input type="submit" id="searchsubmit" value="" />
    </div>
</form>

just copy and paste this code and put it in search box area.. and enjoy searching..:)


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

Friday, 10 January 2014

Get checkbox value in PHP

Get checkbox value in PHP



<form action="index.php" method="post">

 <input type="checkbox" name="language[]" value="php" />PHP<br /> 
<input type="checkbox" name="language[]" value="html" />HTML<br /> 
<input type="checkbox" name="language[]" value="java" />Java<br />
 <input type="checkbox" name="language[]" value="c++" />C++<br /> 
<input type="submit" value="send" />

 </form>


foreach($_POST['language'] as $value)
 {
    echo 'Checked: '.$value.' ';
 }

If you check all the checkboxes, this script will output: 

Checked: php
Checked: html
Checked: java
Checked: c++

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

Thursday, 9 January 2014

Online image Mapping.

Image mapping in HTML

Just go to this website and add your image
Than you have different options right there draw online mapping with associated link.
Online code will generate copy that code and use it like i mentioned below in this POST

http://www.maschek.hu/imagemap/imgmap

How To use code :

Example:
**********************************************************
This code will generate by Online Tool.

<MAP NAME=mymap>

<AREA HREF="/reference/" ALT="HTML and CSS Reference" COORDS="5,5,95,195">
<AREA HREF="/design/" ALT="Design Guide" COORDS="105,5,195,195">
<AREA HREF="/tools/" ALT="Tools" COORDS="205,5,295,195">

</MAP>

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

<IMG SRC="sitemap.gif" ALT="Site map" USEMAP="#mymap" WIDTH=300 HEIGHT=200>

Put this line with proper name (Highlighted in red font) 
---------------------------------------------------------

HTML allows images in different documents to use the same MAP definition from just one file, but many browsers do not support this and require the MAP and image elements to be in the same document.
MAP was originally defined to take one or more AREA elements that specify the coordinates of a clickable region on the image. An example follows:

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


Wednesday, 8 January 2014

Interview questions for Software Developers

Interview questions for fresher Software developers

hi i found a website where lots of important queries were asked. Visit this link

For php

http://www.pcds.co.in/php-interview-questions-and-answer.php

for .net development

http://www.pcds.co.in/dot-net-interview-questions-and-answers.php

Android Interview Questions And Answers

http://www.pcds.co.in/common-android-interview-questions-and-answers.php

Here is the link of blog which helps You alot for preparing interview questions


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

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.

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.

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, 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.

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.

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

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..