Magento Engineer
social
Journal

Programming Blogs to Improve Your Coding Skills!

The industry's top wizards and other experts share their advice and research findings.

How to create wordpress theme?

Introduction to WordPress Theme Development.

Create theme directory under the wordpress wp-content theme folder.
e.g Theme Name : developer
Now add basic files in the theme folder.
index.php
style.css
page.php

Above are very basic files to create wordpress theme.

Below are the some other files to improve your theme functioanlity.
header.php
footer.php
page.php
single.php
functions.php
404.php
screenshot.png

Using these template files you can put template tags within the index.php master file to include these other files where you want them to appear in the final generated page.

To include the header, use get_header().
To include the sidebar, use get_sidebar().
To include the footer, use get_footer().
To include the search form, use get_search_form().

Most Action Hooks are within the core PHP code of WordPress, so your Theme does not have to have any special tags for them to work. But a few Action Hooks do need to be present in your Theme, in order for Plugins to display information directly in your header, footer, sidebar, or in the page body. Here is a list of the special Action Hook Template Tags you need to include:

wp_enqueue_scripts
Used in the theme functions file. Used to load external scripts and stylesheets.

wp_head()
Goes in the <head> element of a theme, in header.php. Example plugin use: add JavaScript code.

wp_footer()
Goes in footer.php, just before the closing </body> tag. Example plugin use: insert PHP code that needs to run after everything else, at the bottom of the footer. Very commonly used to insert web statistics code, such as Google Analytics.

wp_meta()
Typically goes in the <li>Meta</li> section of a Theme's menu or sidebar; sidebar.php template. Example plugin use: include a rotating advertisement or a tag cloud.

comment_form()
Goes in comments.php directly before the file's closing tag (</div>). Example plugin use: display a comment preview.

Ad comes here

WooCommerce: Easily Get Product Info (ID, SKU, $) from $product Object

1. You have access to $product
You can declare the “global $product” inside your function.
// Get Product ID
 
$product->get_id(); (fixes the error: "Notice: id was called incorrectly. Product properties should not be accessed directly")
 
// Get Product General Info
 
$product->get_type();
$product->get_name();
$product->get_slug();
$product->get_date_created();
$product->get_date_modified();
$product->get_status();
$product->get_featured();
$product->get_catalog_visibility();
$product->get_description();
$product->get_short_description();
$product->get_sku();
$product->get_menu_order();
$product->get_virtual();
get_permalink( $product->get_id() );
 
// Get Product Prices
 
$product->get_price();
$product->get_regular_price();
$product->get_sale_price();
$product->get_date_on_sale_from();
$product->get_date_on_sale_to();
$product->get_total_sales();
 
// Get Product Tax, Shipping & Stock
 
$product->get_tax_status();
$product->get_tax_class();
$product->get_manage_stock();
$product->get_stock_quantity();
$product->get_stock_status();
$product->get_backorders();
$product->get_sold_individually();
$product->get_purchase_note();
$product->get_shipping_class_id();
 
// Get Product Dimensions
 
$product->get_weight();
$product->get_length();
$product->get_width();
$product->get_height();
$product->get_dimensions();
 
// Get Linked Products
 
$product->get_upsell_ids();
$product->get_cross_sell_ids();
$product->get_parent_id();
 
// Get Product Variations
 
$product->get_attributes();
$product->get_default_attributes();
 
// Get Product Taxonomies
 
$product->get_categories();
$product->get_category_ids();
$product->get_tag_ids();
 
// Get Product Downloads
 
$product->get_downloads();
$product->get_download_expiry();
$product->get_downloadable();
$product->get_download_limit();
 
// Get Product Images
 
$product->get_image_id();
get_the_post_thumbnail_url( $product->get_id(), 'full' );
$product->get_gallery_image_ids();
 
// Get Product Reviews
 
$product->get_reviews_allowed();
$product->get_rating_counts();
$product->get_average_rating();
$product->get_review_count();
 
// source: https://docs.woocommerce.com/wc-apidocs/class-WC_Product.html


2. You have access to $product_id

If you have access to the product ID (once again, usually the do_action or apply_filters will make this possible to you), you have to get the product object first. Then, do the exact same things as above.
// Get $product object from product ID
 
$product = wc_get_product( $product_id );
 
// Now you have access to (see above)...
 
$product->get_type();
$product->get_name();
// etc.
// etc.


3. You have access to the Order object or Order ID

How to get the product information inside the Order? In this case you will need to loop through all the items present in the order, and then apply the rules above.
// Get $product object from $order / $order_id
 
$order = new WC_Order( $order_id );
$items = $order->get_items();
 
foreach ( $items as $item ) {
 
    $product = wc_get_product( $item['product_id'] );
 
    // Now you have access to (see above)...
 
    $product->get_type();
    $product->get_name();
    // etc.
    // etc.
 
}


4. You have access to the Cart object

How to get the product information inside the Cart? In this case, once again, you will need to loop through all the items present in the cart, and then apply the rules above.
// Get $product object from Cart object
 
$cart = WC()->cart->get_cart();
 
foreach( $cart as $cart_item ){
 
    $product = wc_get_product( $cart_item['product_id'] );
 
    // Now you have access to (see above)...
 
    $product->get_type();
    $product->get_name();
    // etc.
    // etc.
 
}






Ad comes here

What is differences between PHP5 and PHP7 ?

Main differences between PHP5 and PHP7 are as below -

1. PHP 5 is using Zend Engine II while PHP7 is using PHPNG (that is PHP Next Generation)
2. Benchmarks for PHP 7 consistently show speeds twice as fast as PHP 5.6
3. In PHP7, error exception facility called Engine Exception is present in which you can mark the fatal error as exception
4. PHP7 supports 64-bit system while PHP5 does not support it
5. PHP7 introduced New Operators

Ad comes here

Basic & Advanced MySQL Interview Questions with Answers

MySQL Questions with Answers

Question : How can we know the total number of elements of Array?
Answer :
sizeof($array_var)
count($array_var)
If we just pass a simple var instead of a an array it will return 1.

Question : Different Types of Tables in Mysql?
Answer : There are Five Types Tables in Mysql
1)INNODB
2)MYISAM
3)MERGE
4)HEAP
5)ISAM

Question : What is the difference between the functions unlink and unset?
Answer :
unlink() deletes the given file from the file system.
unset() makes a variable undefined.

Question : In how many ways we can retrieve the data in the result set of MySQL using PHP?
Answer : You can do it by 4 Ways
1. mysql_fetch_row.
2. mysql_fetch_array
3. mysql_fetch_object
4. mysql_fetch_assoc


Question : What do DDL, DML, and DCL stand for?
Answer : DDL is the abbreviation for Data Definition Language dealing with database schemas as well as the description of how data resides in the database. An example is CREATE TABLE command. DML denotes Data Manipulation Language such as SELECT, INSERT etc. DCL stands for Data Control Language and includes commands like GRANT, REVOKE etc.

Question : What are the different types of strings in Database columns in MySQL?
Answer : Different types of strings that can be used for database columns are SET, BLOB, VARCHAR, TEX, ENUM, and CHAR.

Question : Is there an object oriented version of MySQL library functions?
Answer : MySQLi is the object oriented version of MySQL and it interfaces in PHP.

Question : How to display Nth highest salary from a table in a MySQL query?
Answer : Let us take a table named employee.

To find Nth highest salary is:
select distinct(salary) from employee order by salary desc limit n-1,1  

If you want to find 3rd largest salary:
select distinct(salary) from employee order by salary desc limit 2,1

Question : What is the difference between mysql_connect and mysql_pconnect?
Answer : Mysql_connect() is used to open a new connection to the database while mysql_pconnect() is used to open a persistent connection to the database. It specifies that each time the page is loaded mysql_pconnect() does not open the database.

Question : How many TRIGGERS are possible in MySql
Answer : Six triggers are possible to use in MySQL database .
1.Before Insert
2.After Insert
3.Before Update
4.After Update
5.Before Delete
6.After Delete

Question : How to delete only the repeated records from a USER table ?
Answer : First we need to select only those records which are repeated giving a constraint :count should be greater than one to make the signle record deletion work. Suppose repeating of record is considered by column name.

SELECT * FROM(SELECT id FROM user GROUP BY name HAVING COUNT(*) > 1) AS A

Then will apply the deletion on those records.
DELETE FROM user WHERE id IN(SELECT * FROM(SELECT id FROM user GROUP BY name HAVING COUNT(*) > 1) AS A)

Ad comes here

How to get all posts from the specific / single category of custom post types in Wordpress ?

<div class="custom-post-entry">
    <?php query_posts( 'post_type=story&category_name=winner'); ?>       
    <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>  
    <?php //get_template_part( 'content', 'page' ); ?>
    <?php get_template_part( 'content', get_post_format() ); ?>
    <?php comments_template( '', true ); ?>
    <div class="clear"></div>
</div><!--post-entry end-->
<?php endwhile; ?>

Ad comes here
Error's and solution's
Update Cookies Preferences