Ronald Joseph

I am professional Web Developer working as Professionally and freelancer in Pakistan

How To Create a Custom post Type — March 4, 2014

How To Create a Custom post Type

<code>add_action(‘init’, ‘member’);

function member() {

$labels = array(

‘name’ => _x(‘Our Members’, ‘post type general name’),

‘singular_name’ => _x(‘Our Members’, ‘post type singular name’),

‘add_new’ => _x(‘Add New’, ‘Our Members item’),

‘add_new_item’ => __(‘Add New Our Members Item’),

‘edit_item’ => __(‘Edit Our Members Item’),

‘new_item’ => __(‘New Our Members Item’),

‘view_item’ => __(‘View Our Members Item’),

‘search_items’ => __(‘Search Portfolio’),

‘not_found’ =>  __(‘Nothing found’),

‘not_found_in_trash’ => __(‘Nothing found in Trash’),

‘parent_item_colon’ => ”

);

$args = array(

‘labels’ => $labels,

‘public’ => true,

‘publicly_queryable’ => true,

‘show_ui’ => true,

‘query_var’ => true,

‘menu_icon’ => get_stylesheet_directory_uri() . ‘/images/admin/wp-logo-small.png’,

‘rewrite’ => true,

‘capability_type’ => ‘post’,

‘hierarchical’ => false,

‘menu_position’ => null,

//’supports’ => array(‘title’,’editor’,’author’,’thumbnail’,’post-thumbnails’,’excerpts’,’trackbacks’,’custom-fields’,’comments’,’revisions’,’page-attributes’)

‘supports’ => array(‘title’,’editor’,’thumbnail’,’custom-fields’)

);

register_post_type( ‘member’ , $args );

}

 </code>

 <code>

<?php $index_query = new WP_Query(array( ‘post_type’ => ‘member’, ‘posts_per_page’ => 4 )); ?>

<?php while ($index_query->have_posts()) : $index_query->the_post(); ?>

<?php endwhile; ?></code>

How to print a String in reverse order — February 10, 2014

How to print a String in reverse order

Most to time this question is asked in Interview, how can we print a string in reverse order with for loop


//error_reporting(NULL);
$string = trim("This is a reversed string");

//find length of string including whitespace
$len =strlen($string);

//slipt sting into an array
$stringExp = str_split($string);

for ($i = $len - 1; $i >=0;$i--)
{
echo $stringExp[$i];
}

OR

you can use


<?php
echo strrev("Hello world!");

// Result :  outputs "!dlrow olleH"
?>
How to sort multi-dimension array according to given price — February 6, 2014

How to sort multi-dimension array according to given price

This code is very helpful for beginner in PHP. To break multi-dimension Array into one single array and then you sort it according to your need, In my scenario, I wanted to Sort it with price High to Low and Low to High so I use array_multisort().

and you can use its sorting type flags, for more details look below at code and sample code link.

$list_box_contents = array(
            array(

             array(
                    "price" => 4.99,
                    "params" => NULL,
                    "text" => "demotext","prices" => 4.99,
                ),

             array(
                    "price" => 4.79,
                    "params" => NULL,
                    "text" => "demotext","prices" => 4.79,
                ),

             array(
                    "price" => 5.10,
                    "params" => NULL,
                    "text" => "demotext","prices" => 5.10,
                ),

             array(
                    "price" => 4.20,
                    "params" => NULL,
                    "text" => "demotext","prices" => 4.20,
                ),

        ),
     array(

             array(
                    "price" => 4.08,
                    "params" => NULL,
                    "text" => "demotext","prices" => 4.08,
                ),

             array(
                    "price" => 4.00,
                    "params" => NULL,
                    "text" => "demotext","prices" => 4.00,
                ),

             array(
                    "price" => 3.20,
                    "params" => NULL,
                    "text" => "demotext",
					"prices" => 3.20,
                ),

             array(
                    "price" => 3.19,
                    "params" => NULL,
                    "text" => "demotext",
					"prices" => 3.19,
                ),

        ),

     array(

             array(
                    "price" => 2.86,
                    "params" => NULL,
                    "text" => "demotext",
					"prices" => 2.86,
                ),

             array(
                    "price" => 3.58,
                    "params" => NULL,
                    "text" => "demotext",
					"prices" => 3.58,
                ),

             array(
                    "price" => 2.92,
                    "params" => NULL,
                    "text" => "demotext",
					"prices" => 2.92,
                ),

             array(
                    "price" => 2.90,
                    "params" => NULL,
                    "text" => "demotext",
					"prices" => 2.90,
                ),

        ),

);

$array = $list_box_contents;
// merging multi-dimension array into one array.
$result = array_merge_recursive($array[0],$array[1],$array[2]);
// now Sort array according to price HIGH to Low
array_multisort($result, SORT_DESC);

print_r($array);
foreach ($result as $key => $val) {
   foreach ($val as $new) {
    }
   echo  $new;
  }

For Output and Sample Code Check Links Below:-

Get raw code – http://phpfiddle.org/api/raw/ed7-rxd

Get execution results – http://phpfiddle.org/api/run/ed7-rxd

Demo Code : http://phpfiddle.org/lite/code/ed7-rxd

WordPress As An Ecommerce Site — August 28, 2013

WordPress As An Ecommerce Site

Whenever you hear about WordPress and or WordPress website, the first come in your mind it’s a blogging site.Wordpress.org has vast range of plugin in his library and also have E-commerce plugin also which is easy to install and operate after a reading through plugin manual.

Building an E-commerce site is not an easy task, you don’t know where to start and implement design to navigation and infrastructure, and you can be left with your head spinning, wondering where to begin in the world. Using the Plugin which are as following, you can develop very handy and easy wordpress E-commerce site. Example e-commerce Plugins:

  • WP e-commerce
    wp-commerce
  • WooCommerce
    woocommerce
  • Cart66 Lite:: WordPress Ecommerce
    cart66
  • iThemes Exchange: Simple Ecommerce
    itheme

If you are well familiar with the admin of wordpress and structure of posting and publishing pages or posts, then it would not be difficult for you to work on any wordpress e-commerce plugin. Also one should maintain these following steps to make a good e-commerce website.

  • Showcase Your Top Sellers
     You should display top sell brands at your index page, it will attract the client and also bring lot of business to your website.
  • Checkout Page: Make It Easy
    The simplest ways for you to make checkout simple for your customers is to reduce the amount of information they need to fill in or provide.
  • User SignUp Form easy
    Signup Process should be simple and fast so user can buy product very fast with any hurdles of filling long forms and also provide social, secure checkout system like Paypal and Sagepay etc.

But I mention only few point for building the e-commerce site, you can building your own strategy before building e-commerce site. Work with the right hosting company that can offer you all of the storage, security and other functionality you want for your WordPress site.