Thursday, 11 August 2011

WordPress Custom Post Type Creation


Before understanding the advanced part of it let me explain you in brief about WordPress. It is an FOSS CMS i.e. content management system powered by PHP and MySQL. Among many features it provides the important features are plug-in architecture and a template system which makes this CMS a robust one. It is used by over 10% of global websites.
Now moving to one of the most exciting features coming in WordPress 3.0 is custom post types, which will vastly expand WordPress’ CMS capabilities. This feature will come handy especially when using WordPress as a CMS.
WordPress Custom Post types are basically different kinds of building blocks that when put together form our website. To understand it in a better way let us create our custom post type called “place”.
Any WordPress system will have functions.php in themes folder. This is the one of our interest. To achieve the purpose you will have to add the following code at the end of the functions.php file.
function post_type_place() {
 register_post_type('place', array('labels' => array('name'=>__('Places'),'add_new_item' => __( 'Add New Place' ),'edit_item' =>__( 'Edit Place' )),
                             'public' => true,
                             'show_ui' => true,
                             'supports' => array('title','author','editor',
                                        'post-thumbnails',
                                        'excerpts',
                                        'trackbacks',
                                        'custom-fields',
                                        'comments',
                                        'revisions'),
                                        'rewrite' => false,
                                        '_builtin' => false,
             '_edit_link' => 'post.php?post=%d',
             'capability_type' => 'post',
             'hierarchical' => false,'query_var' => true
                                )
                      );

  // add to our plugin init function
  //for single template
  global $wp_rewrite;
  $place_structure = '/place/%category%/%place%';
  $wp_rewrite->add_rewrite_tag("%place%", '([^/]+)', "place=");
  $wp_rewrite->add_permastruct('place', $place_structure, false);

  //for displaying tags
  register_taxonomy_for_object_type('post_tag', 'place');

  //for displaying categories
  register_taxonomy_for_object_type('category', 'place');

}
// Add filter to plugin init function

If you want you can use a single page template for displaying custom post.

//function to redirect to place page(templating system)
// Add filter to plugin init function
add_filter('post_type_link', 'place_permalink', 10, 3);
// Adapted from get_permalink function in wp-includes/link-template.php
function place_permalink($permalink, $post_id, $leavename) {
 $post = get_post($post_id);
 $rewritecode = array(
  $leavename? '' : '%postname%',
  '%post_id%',
  '%category%',
  '%author%',
  $leavename? '' : '%pagename%',
 );

 if ( '' != $permalink && !in_array($post->post_status, array('draft', 'pending', 'auto-draft')) ) {
  $unixtime = strtotime($post->post_date);

  $category = '';
  if ( strpos($permalink, '%category%') !== false ) {
   $cats = get_the_category($post->ID);
   if ( $cats ) {
    usort($cats, '_usort_terms_by_ID'); // order by ID
    $category = $cats[0]->slug;
    if($category == "featured") {

     $category = $cats[1]->slug;}

    if ( $parent = $cats[0]->parent )
     $category = get_category_parents($parent, false, '/', true) . $category;

   }
   // show default category in permalinks, without
   // having to assign it explicitly
   if ( empty($category) ) {

    $default_category = get_category( get_option( 'default_category' ) );
    $category = is_wp_error( $default_category ) ? '' : $default_category->slug;
   }
  }

  $author = '';
  if ( strpos($permalink, '%author%') !== false ) {
   $authordata = get_userdata($post->post_author);
   $author = $authordata->user_nicename;
  }
  $rewritereplace =
  array(
   $post->post_name,
   $post->ID,
   $category,
   $author,
   $post->post_name,
  );
  $permalink = str_replace($rewritecode, $rewritereplace, $permalink);
 } else { // if they're not using the fancy permalink option
 }
 return $permalink;
}
add_action('init', 'post_type_place');
Update the permalinks.
The newly created post type (place) will look like this in the WordPress administrator dashboard under the links panel:








Now after creating a custom post you will want to use it. Now see the image below to understand how to add new place in WordPress.










Once you add couple of places the list view under WordPress dashboard will look something like below.







To be able to display the single-type-template using WordPress you will have to use a PHP file by the name single.php. To display newly created custom post you will have to use single-{posttype}.php. So in our case the filename would be single-place.php.

Similarly to archive the custom post use archive-{posttype}.php in WordPress. Normally, the archive-type-template use archive.php file. So in our case the archive template file name would be archive-place.php.

Oracle Programming with PL/SQL Collections

Introduction
PL/SQL applications typically consist of SQL statements intermixed with procedural logic to process data retrieved from the database. If compiled as a stored procedure, your PL/SQL code will reside on the server, an ideal place for programs that require intensive database interaction. Having said that, anytime a software application links up with a database, there is a performance price to be paid. Not only that, programs that continually switch off between code and SQL can become quite complex. PL/SQL collections can address some of these concerns.
Why Collections?
Just about all modern programming languages provide support for collections. A collection can be loosely defined as a group of ordered elements, all of the same type that allows programmatic access to its elements through an index. Commonly used collection types used in the programming world include arrays, maps, and lists.
Storing elements in a collection can provide a number of advantages. For starters, collections can help to simplify code. If you need to process a number of items of a similar type, storing these items in a collection will allow you to loop through each element with ease, referencing each one by an index. In addition, most languages define collection types that contain built-in methods to operate on the collection. Probably the biggest advantage a collection can provide is improved application performance. Developers utilize collections to 'cache' static data that needs to be regularly accessed. This results in reduced calls to a database.
Oracle Collections
Oracle provides three types of PL/SQL collections viz. Associative arrays, nested tables and Varrays. Each type of collection is described in the below section.
Associative Array
Associative arrays are set of key value pairs where each key is unique and is used to locate corresponding value in the array. The key can be integer or a string.
Associative arrays represent data set of arbitrary size with fast lookup of individual element without knowing its position within the array and without having to loop through all array elements. As associative arrays are intended for temporary data storage rather than storing persistent data, they cannot use with SQL statements such as INSERT and SELECT INTO. They can make persistent for a life of database session by declaring the type in package and assigning values in package body.
Varrays
The Varray is short for Variable Array. A Varray stores elements of the same type in the order in which they are added. The number of elements in a Varray must be known at the time of its declaration. In other words, a Varray has a fixed lower and upper bounds, making it most similar to collection types from other programming languages. Once it is created and populated, each element can be accessed by a numeric index.
Nested Table
Nested Tables, like the Varray, can be stored in a relational table as well as function as a PL/SQL program variable. Unlike Varray, nested table require no size specification. In other words, they are unbound.
When to Use What?
Varray
• Use to preserve ordered list.
• Use when working with a fixed set, with a known number of entries.
• Use when you need to store in the database and operate on the Collection as a whole.
Nested Table
• Use when working with an unbounded list that needs to increase dynamically.
• Use when you need to store in the database and operate on elements individually.
Associative Array
• Use when there is no need to store the Collection in the database. Its speed and indexing flexibility make it ideal for internal application use.
Conclusion
Oracle PL/SQL is not a difficult language to learn. However, like all good programming languages, there are many things we can do to maximize efficiency and minimize complexity. Given PL/SQL's power to interact with the database, it can be tempting to simply to fall into the habit of making excessive database calls to do our work. Collections can help you build simpler, faster Oracle database applications, the goal of every good PL/SQL developer.

Monday, 1 August 2011

Can You Imagine Your Internet Life Without GOOGLE?

Have you ever spent a single day online without our friend, Google?
Whether we like it or not, “Google” is almost synonymous with “Internet”. Year after year, Google has developed enough online applications for us to be able to do anything you need to, by only using Google.
Now we have a search engine, an online email service, an IM service, a blogging platform, photo and video sharing applications, a feed reader, an online word processor, an encyclopedia, a web site creator, an online directory and even an Internet browser! Not to mention His PPC advertising system, its main source of revenue.
Now look at the list above. It’s pretty long, isn’t it? Well you know what? It’s only 10% of the programs, applications, widgets or services Google provides today.

Internet without Google?
Now the question is: would it be the Internet possible without Google?
Well, the natural response is yes, it would. But it would be an Internet without its best search engine, without Gmail, You Tube, Google Video, Google Reader, Picassa, Blogger, Orkut, Google Maps, Google Docs, Google Analytics, Google AdSense, Google Chrome, Google Analytics, Google News, Google, Google, and Google!
What a message! It seems almost impossible to work without Google!
But it isn’t. That’s because - fortunately - for almost every service Google provides, there is an alternate service waiting to be discovered. So basically it all depends on your will to make a change. Are we ready to give up all these services and start One day without Google?
Whatever you do, Google is our Big Brother.
Anything we do on the Internet or in “real life”, Google knows about. Maybe these sounds a bit exaggerated, but think about it:
Google knows what we are looking for. Where we are from. What we are interested in. What we’re blogging about. What we are reading. What we advertise. What we click on. What our hobbies.
That’s because we use all these Google services that seem to be tailored to our needs and that require us to put up personal and technical information.
Are we ready to give them up and start One day without Google?
Be careful what you wish, Google knows it.
Funny I should mention the word “tailored”... As we’ve seen in the previous point, Google is our Big Brother, i.e. He knows pretty much about you. And of course He knows everything related to what you need.
Now that kind of information gives Google a tremendous power. Still haven’t figured it out why? Google can develop the exact application or service to fulfill your most ardent needs He knows about. So basically while Google works on creating new needs, He also develops new ways to address them. That’s kind of easy. For Him. And for us too, apparently. Unless we start One day without Google.

No study or explore anymore; there’s Google now.
Here, the issue is more complex than it seems at the first sight. With today’s computers and Internet, the access to information is freer than ever. And Google showed up to organize all that information and serve it on demand. That makes it an excellent way to quickly find information, learn about things you wouldn’t otherwise know about and find an answer to virtually any question.
But an issue arises from all this: why should I study anymore since I find everything on the Internet? And the problem is, for many people this question doesn’t have an obvious answer.
So there is a big risk that we, or at least our children, will forget how to handwrite (word processors rule!), will forget the multiplication table (google it!), will forget anything related to literature, history (there’s wiki), natural sciences and so on.
The problem is, sooner or later we won’t be able to discern what is true and what is false, since all our information sources have moved to online, the truth will lay on the first page of the SERPS (search engine results pages). And just like that...
...Your senses, typical for all live organisms, will all be annihilated.

All that, only if you let it happen. But we can make a change. Have a different view.
Make a point and stand up for it.
We can start One day without Google…

Wednesday, 20 July 2011

VB Scripting - Part 2

Here is one Example of VB Script. Copy below script in notepad, save as outlook.vbs.
Double click outlook.vbs. If the Microsoft outlook is running, this Script will show message: MS Outlook is running.
Or it will show massage: MS Outlook is not running.

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colProcesses = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = 'OUTLOOK.EXE'")
If colProcesses.Count = 0 Then
Wscript.Echo " MS Outlook is not running."
Else
Wscript.Echo " MS Outlook is running."
End If

You might be thinking, “This scripting stuff looks pretty complicated.” Believe it or not, scripting isn’t just for professional computer programmers. There are much more powerful and complicated tools for programmers to use. Don’t get us wrong, a script can be powerful and complicated, but you can also write some fairly simple scripts that can be very helpful. So don’t let the thought of this stuff being “code” scare you off. There are a lot of things you can do pretty easily with no programming experience at all.
One of the advantages of scripting over other types of programming is that for scripting, everything you need is built into the operating system. It needs some acronyms such as VBScript, WSH, and WMI. All of those things are part of scripting, and they’re all built into Windows. You also don’t need fancy, expensive software to write a script. As you saw already, all you really need is Notepad, which, once again, is built-in.
In addition, scripting is specifically designed to help you administer your operating system. Even the most talented programmer would never attempt to create a full-blown software application, such as Word or Excel, using scripts. Scripts allow you to automate system administration tasks.
There are other scripting languages besides VBScript, and there are tools you can use to write scripts other than Notepad. But you can investigate all that on your own after you get a little scripting experience. Most of the scripts and examples on the Script Center use VBScript.
IMPORTANT: One last thing about system administration scripting, and it’s a really important thing to know. For most scripts to run, at least scripts that do anything very interesting, you must have local administrator rights to the machine the script is running against. Many of the scripts available on the Script Center will fail if you’re not running them as a local administrator.

VB Scripting - Part 1

Scripting is just a way to automate getting information to and from your computer (and other computers).
This is the very first thing you need to know to start using scripts to manage your Microsoft Windows systems. On the Script Center (and possibly elsewhere on the Internet, but we can’t vouch for anyone else), you’ll find a lot of pre-made, ready-to-go scripts. A script will look something like this:
Wscript.echo "My very first script."
Yes, that one line is a script. It’s a very simple script, most are longer than this, but it’s still a script. Now you might be wondering what to do with that one line. It’s very simple:
• Open Notepad.
• Copy the script from your browser and paste it into Notepad.
• Save the script with a .vbs extension, such as test.vbs.
Now double click the file test.vbs
If you did this with the script above, you’ll have output that looks like this: My very first script.
Our first script did this: we gave a sentence to the computer and got the same sentence back from the computer. This may not seem like an especially useful feature, but this was just a first step, and one step doesn’t even get you all the way across the room, let alone out the door.
Mr. Amol Vaidya (Technical Director, WIS) always says “If you need to do one task more than one time, just write a script for it”.
There are a number of scenarios where scripts start to get really useful. Here are just a few:
•You have to perform a series of system administration tasks on a regular basis
•You have to perform a series of system administration tasks on several computers
•You want to consolidate and organize the output you get from the computer
•You want to run tasks when you’re not there to interact with the GUI
If you think about some of the work you have to do as a system administrator, you might already be imagining tasks you want to script.

Monday, 4 July 2011

Create Different Shapes using CSS

Cascading Style Sheets (CSS) is a simple mechanism for adding style (e.g., fonts, colors, spacing) to Web documents. Styles define how to display HTML elements. Style sheets are a very powerful tool for the Web site developer. They give you the chance to be completely consistent with the look and feel of your pages, while giving you much more control over the layout and design than straight HTML.
I am going to show you how to create different shapes in CSS
Simple shapes-
Square:







.square {
width: 100px;
height: 100px;
background: red; }

Circle







.circle {
width: 100px;
height: 100px;
background: red;
-moz-border-radius: 50px;
-webkit-border-radius: 50px;
border-radius: 50px; }

Triangle:








.triangle-up {
width: 0;
height: 0;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
border-bottom: 100px solid red; }

Complex Shapes-

Star







.star-six {
width: 0;
height: 0;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
border-bottom: 100px solid red;
position: relative; }

.star-six:after {
width: 0;
height: 0;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
border-top: 100px solid red;
position: absolute;
content: "";
top: 30px;
left: -50px; }

Finally The Smiley Face Using CSS :

Create following divs on Page

<div class="smileyface">
<p class="eyes lefteye"></p>
<p class="eyes righteye"></p>
<div class="smile">
<div class="corner"></div>
<div class="corner right"></div>
</div>
</div>

Create following styles in Style Tag


div.smileyface {
width: 300px;
height: 300px;
position: relative;
border-radius: 150px;
-webkit-border-radius: 150px;
-moz-border-radius: 150px;
display: block;
background: #ffe632;
background: -webkit-gradient(linear, left top, left bottom, from(#fffe8d), to(#f6d23e));
background: -moz-linear-gradient(top, #fffe8d, #f6d23e);
box-shadow: inset 0px -14px 14px rgba(0, 0, 0, .3), 0px 2px 20px rgba(0, 0, 0, .6);
-webkit-box-shadow: inset 0px -14px 14px rgba(0, 0, 0, .3), 0px 2px 20px rgba(0, 0, 0, .6);
-moz-box-shadow: inset 0px -14px 14px rgba(0, 0, 0, .3), 0px 2px 20px rgba(0, 0, 0, .6);
behavior:url(CSS/Corner.htc);/*Gives Corner shapes in IE */
}

p.eyes {
width: 50px;
height: 80px;
background: #222;
border-radius: 100px/160px;
-webkit-border-radius: 100px 160px;
-moz-border-radius: 100px/160px;
position: absolute;
top: 40px;
box-shadow: 0 2px 0 rgba(255,255,255, 0.8);
-webkit-box-shadow: 0 2px 0 rgba(255,255,255, 0.8);
-moz-box-shadow: 0 2px 0 rgba(255,255,255, 0.8);
behavior:url(CSS/Corner.htc);/*Gives Corner shapes in IE */ }

p.eyes.lefteye {
left: 75px;
}

p.eyes.righteye {
right: 75px;
behavior:url(CSS/Corner.htc);/*Gives Corner shapes in IE */ }

div.smile {
width: 200px;
height: 70px;
border: 10px solid #222;
border-top: 0;
background: rgba(0,0,0,0);
-moz-border-radius: 0 0 120px 120px / 0 0 90px 90px;
-webkit-border-radius: 0 0 120px 120px 0 0 90px 90px;
border-radius: 0 0 120px 120px / 0 0 90px 90px;
position: absolute;
bottom: 50px;
left: 38px;
box-shadow: 0 2px 0 rgba(255,255,255, 0.8);
-webkit-box-shadow: 0 2px 0 rgba(255,255,255, 0.8);
-moz-box-shadow: 0 2px 0 rgba(255,255,255, 0.8);
behavior:url(CSS/Corner.htc);/*Gives Corner shapes in IE */ }

div.corner {
width: 10px;
height: 30px;
background: #222;
border-radius: 100px/160px;
-webkit-border-radius: 100px 160px;
-moz-border-radius: 100px/160px;
position: absolute;
top: -12px;
-webkit-transform: rotate(65deg);
-moz-transform: rotate(65deg);
left: -12px;
behavior:url(CSS/Corner.htc);/*Gives Corner shapes in IE */ }

div.corner.right {
left: 202px;
-webkit-transform: rotate(-65deg);
-moz-transform: rotate(-65deg);
behavior:url(CSS/Corner.htc);/*Gives Corner shapes in IE */
}






Google +

Google has just unveiled Google+, its ambitious answer to Facebook.
It seems Google is eager to make a big impact in the social media sector as in the mail, search, photo and document storage domains.
The Google+ project is the company’s social initiative that brings friend streams, group video chat and group texting to Google’s millions of users.
On Google Plus there are only four silos (Home, Photos, Profile, Circles) to click on. Here one cannot find games nor Farmville! It is simple and in Google’s fashion with lot of white space. The ‘Stream' is the equivalent of FB's scroll newsfeed, and there are similar options — to share, edit, host photos and videos, and delete them.
Unlike Facebook, Google Plus allow people to share things with you even if you're not following them. Thus, you'll want to check your Incoming feed now and then to see whether you're missing out on anything interesting from someone you don't follow.
Use the Your Circles option while sharing. Google Plus's Circles system is great for letting you use your Plus account to set barriers between the various groups of people you want to share things with. If most of what you share on Google Plus isn't especially privacy-sensitive, however, use the Your Circles sharing option to automatically share items with all of your circles and avoid the trouble of clicking each individual circle.












Google+ is a bold and dramatic attempt at social front. There’s a reason why Google calls this a “project” rather than a “product” — they don’t want people to think of this as the final product, but as a constantly-evolving entity.
At the moment, Google+ cannot compete with the king of social, but Google doesn’t seem to be in a hurry to take on Mark Zuckerberg’s giant quite yet.