phprockers-logo

Difference between abstract class and interface in php

1 comments

S.No

Abstract Class

Interface Class

1
Abstract class - method must be declared as abstract. Abstract methods doesn’t have any definition. The sub class (extend class) can have the definition for those abstract method. Interface - all the methods by default are abstract methods only. So one cannot declare variables in interfaces. The sub class (implement class) can have all method definition for those methods.

2
The Abstract methods can declare with Access modifiers like public, internal, protected. All methods declared in an interface must be public.

3
Abstract class can contain variables and concrete methods. Interfaces cannot contain variables and concrete methods, but we can possible to define the constants.

4
An abstract class can Inherit only one Abstract class and Multiple inheritance is not possible for Abstract class. A class can implement many interfaces and Multiple interface inheritance is possible.

Get current custom post type in wordpress

0 comments
We can get easily custom post type or normal post type in wordpress by using the post id.
global $posts;
$post_id = $posts->ID;
$post_type = get_post_type($post_id);
echo $post_type;

Get current post id in wordpress

0 comments
2 ways, we have to get current post id in wordpress
First way: 
global $posts;
$current_post_id = $posts->ID;
Second way:  

global $wp_query;
$current_post_id = $wp_query->post->ID;

Get Category Name from Post ID in WordPress

0 comments
Get the category name by using the post id in wordpress,
Step 1: First we have to get the post id
global $posts;
$post_id = $posts->ID;

Step 2: After the get the post id, then we get the category is very simple.
$category = get_the_category($postID);

$category_name = $category->cat_name

Simple way to create a widget in wordpress

1 comments
First Step: Goto this directory-localhost/yourwordpressname/wp-content/plugins.
Second Step: Create a folder for creating a widget in above directory.

Third Step: Inside the folder, Create a .php file and copy below codes.
Fourth Step: Goto wordpress administrator, see left sidebar, click plugins and activate your plugin.
Fifth Step: Finally Goto wordpress widget  and find the your widget name here. Then you have to use, where you want in widgetized area in wordpress.

Guides for creating a complete widgets in WordPress 3.3

0 comments
The first thing we have to do is load our widget when necessary. WordPress provides the widgets_init action hook that will allow us to do this. In WordPress 3.1, this action hook is fired right after the default WordPress widgets have been registered.

Note: This can be used to all wordpress versions


<?php

/**
* Plugin Name: Example Widget
* Plugin URI: http://phprockers.blogspot.com/p/wordpress.html
* Description: A widget that serves as an example for developing more advanced widgets.
* Version: 1.0
* Author: Ramakrishnan V.
* Author URI: http://phprockers.blogspot.com

*
*/

Uploading Files with PHP

1 comments
This script will allow you to upload files from your browser to your hosting, using PHP. The first thing we need to do is create an HTML form that allows people to choose the file they want to upload. 

<form enctype="multipart/form-data" action="upload.php" method="POST"> 
<lable> Please choose a file: </lable>
<input name="uploaded" type="file" /><br /> 
<input type="submit" value="Upload" /> 
</form> 
 
This form sends data to the file "upload.php". Then we can easily get the uploaded information using file function in upload.php.