Thursday, 6 March 2014

Wordpress Interview Question and Answer.

1. How to get the postid in wordpress?
We can get the postid
global $wp_query;
$postid = $wp_query->post->ID;
echo $postid;

2. How to get the post meta value in worpdress?
We can get the post meta value throw postid.
 For example here post Custom Field name : comapny name
 get_post_meta($postid, 'Company name', true);

3. How to check if the post has a Post Thumbnail assigned to it.
if ( has_post_thumbnail() )  // check if the post has a Post Thumbnail assigned to it.
   {                                
      the_post_thumbnail();  
   }

4.how to get the wordpress featued image and how to change the image width and height.
We can get the featurd image wordpress function
   the_post_thumbnail(); //here we can get the wordpress featured image thumbnail
  the_post_thumbnail( array(100,100) );     // here we can change the image size.

5. How to get the specified category post only in wordpress?
Here we can get the all post in category id based.
<?php query_posts("cat=106 && per_page=5");// here 106 is the category id  ?>
<?php while ( have_posts() ) : the_post(); ?>
<h3><?php the_title(); // here we can get the post title. this is the wordpress free defind function ?></h3>
<?php  endwhile; ?>

6. How to hide the top admin bar at the frontend of wordpress 3.4?
Add the below mentioned code in the theme(active) function.php 
add_filter(‘show_admin_bar’, ‘__return_false’);
                               (or)
Add the below code in the active theme stylesheet
#wpadminbar {
display: none; visibility: hidden;
}
7. Run Any Query on the Database for WordPress.
The query function allows you to execute any SQL query on the WordPress database. It is best to use a more specific function (see below), however, for SELECT queries.
 <?php $wpdb->query('query'); ?>
8. What are rules to follow in wordpress plugin development?
  • Find a unique name
  • Setup a prefix (related to your brand)
  • Create the plugin’s folder
  • Create sub-folders for PHP files, assets, and translations
  • Create the main plugin file and fill in obligatory header information
  • Create a readme.txt file
  • Use proper constants and functions to detect paths to plugin files
  • Create additional PHP files and include them inside the main one
  • Create activation and deactivation functions
  • Create an uninstall script

9. What is hooks and types of hooks in wordpress?
Hooks are provided by WordPress to allow your plugin to ‘hook into’ the rest of WordPress; that is, to call functions in your plugin at specific times, and thereby set your plugin in motion. There are two kinds of hooks:
  1. Actions: Actions are the hooks that the WordPress core launches at specific points during execution, or when specific events occur. Your plugin can specify that one or more of its PHP functions are executed at these points, using the Action API.
  2. Filters: Filters are the hooks that WordPress launches to modify text of various types before adding it to the database or sending it to the browser screen. Your plugin can specify that one or more of its PHP functions is executed to modify specific types of text at these times, using the Filter API.

10. Can I rename the WordPress folder?
If you have not already installed WordPress, you can rename the folder with the WordPress files, before, or even after uploading the files.
If you have already installed WordPress, and you want to rename the folder, login to the weblog as the administrator and change the following settings in Settings > General:
WordPress address (URI):
Blog address (URI):
Once you have done this, you can rename the directory or folder with the WordPress files in it.
11. Do I really need MySQL?
You certainly need the MySQL database server to power your WordPress blog. In fact, WordPress only supports the MySQL database server. Listed are the PHP and MySQL requirements:
WordPress server requirements for Version 3.2:
PHP version 5.2.4 or greater
MySQL version 5.0.15 or greater
(Optional)(Required for MultiSite) Apache mod_rewrite module (for clean URIs known as Permalinks)
12. Why does WordPress use MySQL?
MySQL is extremely fast. It is also the most widely available database server in the world. Open-source and free, MySQL is supported by thousands of low-cost Linux (and Windows!) hosts, which means a very low barrier to entry for anyone wanting to start a WordPress (or database-driven) website. MySQL’s documentation is useful, cogent and thorough. (Note: it may be intimidating if you are new to all this.) Add to all that the fact that users are able to directly manipulate MySQL with phpMyAdmin, developed expressly for that purpose, and it is obvious that MySQL is the best choice. Of course, WordPress insists on the best.
13. How do I disable comments?
First, unchecked Allow people to post comments on the article on the Options > Discussion panel. This will only disable comments on future posts. Now, to completely disable comments, you will have to edit each past post and uncheck Allow Comments from the Write Post SubPanel. Alternatively, you could run this MySQL query from the command line on a shell account or using phpMyAdmin: UPDATE wp_posts SET comment_status=”closed”;
If your goal is to permanently disable comments, then you should delete the wp-comments-post.php file as well.
14. What are the features of Wordpress?
  • Simplicity Simplicity makes it possible for you to get online and get publishing, quickly. Nothing should get in the way of you getting your website up and your content out there. WordPress is built to make that happen.
  • Flexibility With WordPress, you can create any type of website you want: a personal blog or website, a photoblog, a business website, a professional portfolio, a government website, a magazine or news website, an online community, even a network of websites. You can make your website beautiful with themes, and extend it with plugins. You can even build your very own application.
  • Publish with Ease If you’ve ever created a document, you’re already a whizz at creating content with WordPress. You can create Posts and Pages, format them easily, insert media, and with the click of a button your content is live and on the web.
  • Publishing Tools WordPress makes it easy for you to manage your content. Create drafts, schedule publication, and look at your post revisions. Make your content public or private, and secure posts and pages with a password.
  • User Management Not everyone requires the same access to your website. Administrators manage the site, editors work with content, authors and contributors write that content, and subscribers have a profile that they can manage. This lets you have a variety of contributors to your website, and let others simply be part of your community.
  • Media Management They say a picture says a thousand words, which is why it’s important for you to be able to quickly and easily upload images and media to WordPress. Drag and drop your media into the uploader to add it to your website. Add alt text, captions, and titles, and insert images and galleries into your content. We’ve even added a few image editing tools you can have fun with.
  • Full Standards Compliance Every piece of WordPress generated code is in full compliance with the standards set by the W3C. This means that your website will work in today’s browser, while maintaining forward compatibility with the next generation of browser. Your website is a beautiful thing, now and in the future.
  • Easy Theme System WordPress comes bundled with two default themes, but if they aren’t for you there’s a theme directory with thousands of themes for you to create a beautiful website. None of those to your taste? Upload your own theme with the click of a button. It only takes a few seconds for you to give your website a complete makeover.
  • Extend with Plugins WordPress comes packed full of features for every user, for every other feature there’s a plugin directory with thousands of plugins. Add complex galleries, social networking, forums, social media widgets, spam protection, calendars, fine-tune controls for search engine optimization, and forms.
  • Built-in Comments Your blog is your home, and comments provide a space for your friends and followers to engage with your content. WordPress’s comment tools give you everything you need to be a forum for discussion and to moderate that discussion.
  • Search Engine Optimized When the head of Google’s web spam team says that WordPress is a great choice, taking care of 80-90% of the mechanics of search engine optimization for you, you know you’re on to a good thing. For more fine-grained SEO control, there are plenty of SEO plugins to take care of that for you.
  • Multilingual WordPress is available in more than 70 languages. If you or the person you’re building the website for would prefer to use WordPress in a language other than English, that’s easy to do.
  • Easy Installation and Upgrades WordPress has always been easy to install and upgrade. If you’re happy using an FTP program, you can create a database, upload WordPress using FTP, and run the installer. Not familiar with FTP? Plenty of web hosts offer one-click WordPress installers that let you install WordPress with, well, just one click!
  • Importers Using blog or website software that you aren’t happy with? Running your blog on a hosted service that’s about to shut down? WordPress comes with importers for blogger, LiveJournal, Movable Type, TypePad, Tumblr, and WordPress. If you’re ready to make the move, we’ve made it easy for you.
  • Own Your Data Hosted services come and go. If you’ve ever used a service that disappeared, you know how traumatic that can be. If you’ve ever seen adverts appear on your website, you’ve probably been pretty annoyed. Using WordPress means no one has access to your content. Own your data, all of it – your website, your content, your data.
  • Freedom WordPress is licensed under the GPL which was created to protect your freedoms. You are free to use WordPress in any way you choose: install it, use it, modify it, distribute it. Software freedom is the foundation that WordPress is built on.
  • Community As the most popular open source CMS on the web, WordPress has a vibrant and supportive community. Ask a question on the support forums and get help from a volunteer, attend a WordCamp or Meetup to learn more about WordPress, read blogs posts and tutorials about WordPress. Community is at the heart of WordPress, making it what it is today.
  • Contribute You can be WordPress too! Help to build WordPress, answer questions on the support forums, write documentation, translate WordPress into your language, speak at a WordCamp, write about WordPress on your blog. Whatever your skill, we’d love to have you!

Developer Features

For developers, we’ve got lots of goodies packed under the hood that you can use to extend WordPress in whatever direction takes your fancy.
  • Plugin System The WordPress APIs make it possible for you to create plugins to extend WordPress. WordPress’s extensibility lies in the thousands of hooks at your disposal. Once you’ve created your plugin, we’ve even got a plugin repository for you to host it on.
  • Theme System Create WordPress themes for clients, customers, and for WordPress users. TheWordPress API provides the extensibility to create themes as simple or as complex as you wish. If you want to give your theme away for free you can give it to users in the Theme Repository
  • Application Framework If you want to build an application, WordPress can help with that too. Under the hood WordPress provides a lot of the features that your app will need, things like translations, user management, HTTP requests, databases, URL routing and much, much more.
  • Custom Content Types WordPress comes with default content types, but for more flexibility you can add a few lines of code to create your own custom post types, taxonomies, and metadata. Take WordPress in whatever direction you wish.
  • The Latest Libraries WordPress comes with the latest script libraries for you to make use of. These include jQuery, Plupload, Underscore.js and Backbone.js. We’re always on the lookout for new tools that developers can use to make a better experience for our users.
15. Who is the founder of WordPress?
      Matthew Charles Mullenweg.
16. How many tables a default WordPress will have?
A default wordpress will have 11 tables. They are-
1. wp_commentmeta
2. wp_comments
3. wp_links
4. wp_options
5. wp_postmeta
6. wp_posts
7. wp_terms
8. wp_term_relationships
9. wp_term_taxonomy
10.wp_usermeta
11.wp_users

Sunday, 2 March 2014

Create a table and insert a column of anothe table with related data in new table.

CREATE TABLE mystudent
  AS (SELECT name FROM student);

Copy one column value in another column.

Table Name: list
number | test
123456 | 123456
123486 | 123486
232344 | 23234
UPDATE `list` SET test=number;

Concatenate two column with another text and insert in third column.

+-----+------+----------+-------------+
| id  | abbr | trans_id | forth_field |
+-----+------+----------+-------------+
| 10  | mm   | mm0010   |             |
+-----+------+----------+-------------+

UPDATE table
SET forth_field = CONCAT(abbr, '00', id)
+-----+------+----------+-------------+
| id  | abbr | trans_id | forth_field |
+-----+------+----------+-------------+
| 10  | mm   | mm0010   | mm0010      |
+-----+------+----------+-------------+

Wednesday, 26 February 2014

Common PHP Job Interview Questions and Answers

In PHP what is the difference between a Class and an Interface?
Interfaces do not contain business logic, only method signatures that define a template that any classes implementing the interface must contain. Lets take an auto mobile for example. If we were to create and interface for a car we would want to define a few methods like drive, stop, turn left , turn right. This mean that any vehicle that is a car (aka implements the interface car) must have methods for these things, If they do not PHP will throw an error. So if your car is an BMW , Honda or Ford it must be able to stop. How it stops is up to each car (or PHP class) but it must be able to stop. Technically we can decide not to use an interface for cars, but then some types of cars are not forced to have a "stop" method.

What is MVC?
Most programmers know this, but interviewers will likely look for a deep understanding of MVC, and some explanation or examples on how/why/ when you used it. 

MVC- Model, View, Controller - is simply a way of organizing your code into 3 separate layers each with there own job. 

Model - Usually contains data access code and all of you business logic code. 
View - Contains markup/design code, generally html,xml, json. 
Controller - Usually contains very little code, just whatever is needed to call the Model code and render the View code.

What does ob_start do?
Makes it so PHP does not output anything. Companies ask this because many large frameworks wrap a bunch of code in ob_start() and ob_get_clean(). So understanding how that function works is pretty important.

I want to share this great php utility: the output buffering, it is sometimes very usefull. So what it does ?
The PHP output buffering will save all the server outputs ( html and php prints) to a string variable.

So to start buffering, use ob_start(); this will keep saved any output.
Then you use $variable = ob_get_clean(); to stop buffering, and copy the buffer content to the variable.

Here are few samples of the use of ob_start() and ob_get_clean()


<?php ob_start(); //Turn on output buffering ?>
Hello world, <a href="http://www.blogger.com/myotherpage.php">link</a>
<div class="style">Content</div>
<?php $var = ob_get_clean(); //copy current buffer contents into $message variable and delete current output buffer ?>


Now the content of the variable $var should be:

Hello word, <a href="http://www.blogger.com/myotherpage.php">link</a>
<div class="style">Content</div>


Another example (with php outputs buffered)

<?php ob_start(); ?>
Hello world, <?php echo "My Website"; ?>
Thank you.
<?php $var = ob_get_clean(); ?>

And this will be the content of $var:
Hello world, My Website
Thank you

What is the difference between CHAR AND VARCHAR?
The CHAR and VARCHAR types are similar, but differ in the way they are stored and retrieved.
The length of a CHAR column is fixed to the length that you declare when you create the table.
The length can be any value between 1 and 255. When CHAR values are stored, they are right-padded with spaces to the specified length. When CHAR values are retrieved, trailing spaces are removed.

How do you get the month from a timestamp?
SELECT MONTH(january_timestamp) from tablename;

Where MyISAM table is stored?
Each MyISAM table is stored on disk in three files.
The ‘.frm’ file stores the table definition.
The data file has a ‘.MYD’ (MYData) extension.
The index file has a ‘.MYI’ (MYIndex) extension

How to get size & type of uploaded image?
list($width, $height, $type) = getimagesize($_FILES['photo_file']['tmp_name']);
How can we submit a form without a submit button?
The main idea behind this is to use Java script submit( function in order to submit the form without explicitly clicking any submit button. You can attach the document.formname.submit( ) method to onclick, onchange events of different inputs and perform the form submission. you
can even built a timer function where you can automatically submit the form after xx seconds once the loading is done (can be seen in online test sites.
How can we create a database using PHP and MySQL?
We can create MySQL database with the use of
mysql_create_db(“Database Name”);
What are the different tables present in MySQL?
Total  types of tables we can create
. MyISAM
. Heap
. Merge
. INNO DB
. ISAM
MyISAM is the default storage engine as of MySQL . and as a result if we do not specify the table name explicitly it will be assigned to the default engine.

Top 50 OOP Interview Questions

1.       What is OOPS?
OOPS is abbreviated as Object Oriented Programming system in which programs are considered as a collection of objects. Each object is nothing but an instance of a class.
2.       Write basic concepts of OOPS?
Following are the concepts of OOPS and are as follows:.
  1. Abstraction.
  2. Encapsulation.
  3. Inheritance.
  4. Polymorphism.
3.       What is a class?
A class is simply a representation of a type of object. It is the blueprint/ plan/ template that describe the details of an object.
4.       What is an object?
Object is termed as an instance of a class, and it has its own state, behavior and identity.
5.       What is Encapsulation?
Encapsulation is an attribute of an object, and it contains all data which is hidden. That hidden data can be restricted to the members of that class.
Levels are Public,Protected, Private, Internal and Protected Internal.
6.       What is Polymorphism?
Polymorphism is nothing butassigning behavior or value in a subclass to something that was already declared in the main class. Simply, polymorphism takes more than one form.
7.       What is Inheritance?
Inheritance is a concept where one class shares the structure and behavior defined in another class. Ifinheritance applied on one class is called Single Inheritance, and if it depends on multiple classes, then it is called multiple Inheritance.
8.       What are manipulators?
Manipulators are the functions which can be used in conjunction with the insertion (<<) and extraction (>>) operators on an object. Examples are endl and setw.
9.       Define a constructor?
Constructor is a method used to initialize the state of an object, and it gets invoked at the time of object creation. Rules forconstructor are:.
  • Constructor Name should be same asclass name.
  • Constructor must have no return type.
10.   Define Destructor?
Destructor is a method which is automatically called when the object ismade ofscope or destroyed. Destructor name is also same asclass name but with the tilde symbol before the name.
11.   What is Inline function?
Inline function is a technique used by the compilers and instructs to insert complete body of the function wherever that function is used in the program source code.
12.   What is avirtual function?
Virtual function is a member function ofclass and its functionality can be overridden in its derived class. This function can be implemented by using a keyword called virtual, and it can be given during function declaration.
Virtual function can be achieved in C++, and it can be achieved in C Languageby using function pointers or pointers to function.
13.   What isfriend function?
Friend function is a friend of a class that is allowed to access to Public, private or protected data in that same class. If the function is defined outside the class cannot access such information.
Friend can be declared anywhere in the class declaration, and it cannot be affected by access control keywords like private, public or protected.
14.   What is function overloading?
Function overloading is defined as a normal function, but it has the ability to perform different tasks. It allowscreation of several methods with the same name which differ from each other by type of input and output of the function.
Example
void add(int& a, int& b);
void add(double& a, double& b);
void add(struct bob& a, struct bob& b);
15.   What is operator overloading?
Operator overloading is a function where different operators are applied and depends on the arguments. Operator,-,* can be used to pass through the function , and it has their own precedence to execute.
Example:
class complex {
double real, imag;
public:
complex(double r, double i) :
real(r), imag(i) {}
complex operator+(complex a, complex b);
complex operator*(complex a, complex b);
complex& operator=(complex a, complex b);
}
a=1.2, b=6
16.   What is an abstract class?
An abstract class is a class which cannot be instantiated. Creation of an object is not possible withabstract class , but it can be inherited. An abstract class can contain only Abstract method.
17.   What is a ternary operator?
Ternary operator is said to be an operator which takes three arguments. Arguments and results are of different data types , and it is depends on the function. Ternary operator is also called asconditional operator.
18.   What is the use of finalize method?
Finalize method helps to perform cleanup operations on the resources which are not currently used. Finalize method is protected , and it is accessible only through this class or by a derived class.
19.   What are different types of arguments?
A parameter is a variable used during the declaration of the function or subroutine and arguments are passed to the function , and it should match with the parameter defined. There are two types of Arguments.
  • Call by Value – Value passed will get modified only inside the function , and it returns the same value whatever it is passed it into the function.
  • Call by Reference – Value passed will get modified in both inside and outside the functions and it returns the same or different value.

20.   What is super keyword?
Super keyword is used to invoke overridden method which overrides one of its superclass methods. This keyword allows to access overridden methods and also to access hidden members of the superclass.
It also forwards a call from a constructor to a constructor in the superclass.
21.   What is method overriding?
Method overriding is a feature that allows sub class to provide implementation of a method that is already defined in the main class. This will overrides the implementation in the superclass by providing the same method name, same parameter and same return type.
22.   What is an interface?
An interface is a collection of abstract method. If the class implements an inheritance, and then thereby inherits all the abstract methods of an interface.
23.   What is exception handling?
Exception is an event that occurs during the execution of a program. Exceptions can be of any type – Run time exception, Error exceptions. Those exceptions are handled properly through exception handling mechanism like try, catch and throw keywords.
24.   What are tokens?
Token is recognized by a compiler and it cannot be broken down into component elements. Keywords, identifiers, constants, string literals and operators are examples of tokens.
Even punctuation characters are also considered as tokens – Brackets, Commas, Braces and Parentheses.
25.   Difference between overloading and overriding?
Overloading is static binding whereas Overriding is dynamic binding. Overloading is nothing but the same method with different arguments , and it may or may not return the same value in the same class itself.
Overriding is the same method names with same arguments and return types associates with the class and its child class.
26.   Difference between class and an object?
An object is an instance of a class. Objects hold any information , but classes don’t have any information. Definition of properties and functions can be done at class and can be used by the object.
Class can have sub-classes, and an object doesn’t have sub-objects.
27.   What is an abstraction?
Abstraction is a good feature of OOPS , and it shows only the necessary details to the client of an object. Means, it shows only necessary details for an object, not the inner details of an object. Example – When you want to switch On television, it not necessary to show all the functions of TV. Whatever is required to switch on TV will be showed by using abstract class.
28.   What are access modifiers?
Access modifiers determine the scope of the method or variables that can be accessed from other various objects or classes. There are 5 types of access modifiers , and they are as follows:.
  •  Private.
  • Protected.
  • Public.
  • Friend.
  • Protected Friend.
29.   What is sealed modifiers?
Sealed modifiers are the access modifiers where it cannot be inherited by the methods. Sealed modifiers can also be applied to properties, events and methods. This modifier cannot be applied to static members.

30.   How can we call the base method without creating an instance?
Yes, it is possible to call the base method without creating an instance. And that method should be,.
Static method.
Doing inheritance from that class.-Use Base Keyword from derived class.
31.   What is the difference between new and override?
The new modifier instructs the compiler to use the new implementation instead of the base class function. Whereas, Override modifier helps to override the base class function.
32.   What are the various types of constructors?
There are three various types of constructors , and they are as follows:.
-          Default Constructor – With no parameters.
-          Parametric Constructor – With Parameters. Create a new instance of a class and also passing arguments simultaneously.
-          Copy Constructor – Which creates a new object as a copy of an existing object.
33.   What is early and late binding?
Early binding refers to assignment of values to variables during design time whereas late binding refers to assignment of values to variables during run time.
34.   What is ‘this’ pointer?
THIS pointer refers to the current object of a class. THIS keyword is used as a pointer which differentiates between the current object with the global object. Basically, it refers to the current object.
35.   What is the difference betweenstructure and a class?
Structure default access type is public , but class access type is private. A structure is used for grouping data whereas class can be used for grouping data and methods. Structures are exclusively used for dataand it doesn’t require strict validation , but classes are used to encapsulates and inherit data which requires strict validation.
36.   What is the default access modifier in a class?
The default access modifier of a class is Private by default.
37.   What is pure virtual function?
A pure virtual function is a function which can be overridden in the derived classbut cannot be defined. A virtual function can be declared as Pure by using the operator =0.
Example -.
Virtual void function1() // Virtual, Not pure
Virtual void function2() = 0 //Pure virtual
38.   What are all the operators that cannot be overloaded?
Following are the operators that cannot be overloaded -.
  1. Scope Resolution (:: )
  2. Member Selection (.)
  3. Member selection through a pointer to function (.*)

39.   What is dynamic or run time polymorphism?
Dynamic or Run time polymorphism is also known as method overriding in which call to an overridden function is resolved during run time, not at the compile time. It means having two or more methods with the same name,same signature but with different implementation.
40.   Do we require parameter for constructors?
No, we do not require parameter for constructors.
41.   What is a copy constructor?
This is a special constructor for creating a new object as a copy of an existing object. There will be always only on copy constructor that can be either defined by the user or the system.
42.   What does the keyword virtual represented in the method definition?
It means, we can override the method.
43.   Whether static method can use non static members?
False.
44.   What arebase class, sub class and super class?
Base class is the most generalized class , and it is said to be a root class.
Sub class is a class that inherits from one or more base classes.
Super class is the parent class from which another class inherits.
45.   What is static and dynamic binding?
Binding is nothing but the association of a name with the class. Static binding is a binding in which name can be associated with the class during compilation time , and it is also called as early Binding.
Dynamic binding is a binding in which name can be associated with the class during execution time , and it is also called as Late Binding.
46.   How many instances can be created for an abstract class?
Zero instances will be created for an abstract class.
47.   Which keyword can be used for overloading?
Operator keyword is used for overloading.
48.   What is the default access specifier in a class definition?
Private access specifier is used in a class definition.
49.   Which OOPS concept is used as reuse mechanism?
Inheritance is the OOPS concept that can be used as reuse mechanism.
50.   Which OOPS concept exposes only necessary information to the calling functions?
Data Hiding / Abstraction

How calulation total value for HTML input text?

<script> $j(document).ready(function(){ $j(":text").keyup(function(){ if (isNaN($j(this).val())) { alert(...