How to use custom post type in wordpress

From wordpress 3.0 version release wordpress gives the facility to add a custom post type functionality. With custom post type wordpress is became more powerful and expendable and more advanced We given info about, How to use custom post type in wordpress.

How to use custom post type in wordpress

WordPress recognized the need to people and industry and they introduced the custom post type. In this tutorial I will tell you how to use the custom post type very effectively.

Adding Custom post type is very easy. Using theme or plugin file you can add the custom post types in wordpress admin area.

Here I am going to give you example using wordpress theme files. Open you functions.php file and copy paste the following code in that file.


add_action('init', 'create_product');
 function create_product() {
 $product_args = array(
 'label' => __('Product'),
 'singular_label' => __('Product'),
 'public' => true,
 'show_ui' => true,
 'capability_type' => 'post',
 'hierarchical' => false,
 'rewrite' => true,
 'supports' => array('title', 'editor', 'thumbnail')
 );
 register_post_type('product',$product_args);
 }

How to use custom post type in wordpress
How to use custom post type in wordpress

The function register_post_type() accepts two arguments: the name we want to give our post type, and a list of arguments used to create that post type, which we put in an array called $args.

Using above code that code will add the product post type to wordpress panel.

Now you can add the meta fields to custom post type. Use the following code in file for add the meta fields. Custom meta fields function is available from quite some time. add_meta_box() function is very useful to adding custom fields to wordpress post.


<?php

 add_action("admin_init", "add_product");
 add_action('save_post', 'update_thumbnail_url');
 function add_product(){
 add_meta_box("product_details", "product Options", "product_options", "product", "normal", "low");
 }
 function product_options(){
 global $post;
 $custom = get_post_custom($post->ID);
 $thumbnail_url = $custom["thumbnail_url"][0];
 $product_info = $custom["product_info"][0];
 $product_infos = $custom["product_infos"][0];
 $video_code = $custom["video_code"][0];

?>
 <div id="product-options">
 <label>Thumbnail URL:</label><input size="100" name="thumbnail_url" value="<?php echo $thumbnail_url; ?>" /><br>
 <label>Product Info:</label><input size="100" name="product_info" value="<?php echo $product_info; ?>" /><br>
 <img src="<?php echo $product_infos; ?>"><br>
 <label>Video Code:</label><textarea cols="50" rows="5" name="video_code"><?php $video_code; ?></textarea>
 </div><!--end product-options-->
<?php
 }
 function update_thumbnail_url(){
 global $post;
 update_post_meta($post->ID, "thumbnail_url", $_POST["thumbnail_url"]);
 update_post_meta($post->ID, "product_info", $_POST["product_info"]);
 update_post_meta($post->ID, "video_code", $_POST["video_code"]);

 }
?>

Using following code you can see the product information in edit product page and you can able to see the all information in for edit. Admin will know which fields are available to edit.

How to use custom post type in wordpress
How to use custom post type in wordpress

<?php
add_action("manage_posts_custom_column",  "product_custom_columns");
add_filter("manage_edit-product_columns", "product_edit_columns");

function product_edit_columns($columns){
 $columns = array(
 "cb" => "<input type=\"checkbox\" />",
 "title" => "Product Title",
 "thumbnail_url" => "Thumbnail URL",
 "product_info" => "Product Info",
 "video_code" => "Video Code",
 );
 return $columns;
}
function product_custom_columns($column){
 global $post;
 switch ($column) {
 case "thumbnail_url":
 $custom = get_post_custom();
 echo $custom["thumbnail_url"][0];
 break;
 case "product_info":
 $custom = get_post_custom();
 echo $custom["product_info"][0];
 break;
 case "video_code":
 $custom = get_post_custom();
 echo $custom["video_code"][0];
 break;
 }
}

?>

Using custom post type and add meta tag you can develop very nice applications. Now I am going to show you how you can extract the custom posts in wordpress frontend.

Using wp_query you can easily extract product posts. In any category page or conditionally you can use following code.


$loop = new WP_Query( array( 'post_type' => 'product', 'posts_per_page' => 10 ) );
while ( $loop->have_posts() ) : $loop->the_post();
 the_title();
the_content();
global $post;
 $custom = get_post_custom($post->ID);
echo $thumbnail_url = $custom["thumbnail_url"][0];
echo $product_info = $custom["product_info"][0];
echo $video_code = $custom["video_code"][0];
 echo '<div>';
 the_content();
 echo '</div>';
endwhile;

Or you can create the custom theme page using following code. Just create product.php page in your wordpress theme folder.Put following code in that file.


<?php

/*Template Name: Product*/

?>

<?php get_header(); ?>

<div id="container">

<div id="content" role="main">

<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>

<?php $recent = new WP_Query('post_type=product&posts_per_page=10′); while($recent->have_posts()) : $recent->the_post();?>

<?php the_title( '<h2><a href="' . get_permalink() . '" title="' . the_title_attribute( 'echo=0′ ) . '" rel="bookmark">', '</a></h2>' ); ?>

<div>

<?php the_content(); ?>

<?php

the_content();
global $post;
$custom = get_post_custom($post->ID);
echo $thumbnail_url = $custom["thumbnail_url"][0];
echo $product_info = $custom["product_info"][0];
echo $video_code = $custom["video_code"][0];

?>

<?php wp_link_pages( array( 'before' => '<div>' . __( 'Pages:', 'wordpressapi' ), 'after' => '</div>' ) ); ?>

<?php edit_post_link( __( 'Edit', 'wordpressapi' ), '<span>', '</span>' ); ?>

</div><!– .entry-content –>

<?php comments_template( ", true ); ?>

<?php endwhile; ?>

</div><!– #content –>

</div><!– #container –>

<?php get_sidebar(); ?>

<?php get_footer(); ?>

Now create product page and product as template.

If you have any issues or doubts then write to me.

WordPress changed the statistic graph

Today when I logged to my wordpress blog account and looked at dashboard, I saw the new changed statistic graph.
The new statistic graph is looking really very cool. New graph version is better for those who are visually improved so nicely.

WordPress changed the statistic graph

For wordpress blogger and website users this news is really great.

Seeing this graph I must say you will miss having the grand total of both syndicated and on-site views for an entry.

As we know we need to updgrade the “WordPress.com Stats” wordpress plugin to see the updated stats in your hosted wordpress blogs.
You can download or update the wordpress stat plugin using following URL
http://wordpress.org/extend/plugins/stats/

Wordpress changed the statistic graph
WordPress changed the statistic graph

What wordpress is saying about changed Stat in Twitter.
Sexy Stats: http://wp.me/pf2B5-1n9

As per wordpress:
Each module can be opened and closed, moved, or hidden completely. If you don’t want to see a module, minimize it with one click or use the Screen Options to keep it out of sight. Customize everything and view stats the way you want to.

As you hover over each bar in the chart it changes color and displays a tooltip, giving you more information about the data. If the chart is showing data by day, Saturdays and Sundays have a light gray background to make it easier to see weekly patterns. Under the chart you’ll notice a new area, called “fortune cookies,” where we’ll highlight key stats.

During the redesign we went with bar charts because the end of one day and the beginning of another shouldn’t be connected. Each day starts at zero and we think bar charts work much better for this type of data. We hope you’ll agree once you get used to the change.

In this first phase of the stats redesign we’ve focused on the main page. This will allow us to collect feedback from you so we can tweak everything as we go. We’ve only mentioned a few of the highlights here, so take your stats for a drive around town to get used to the feel. Let us know what you like and what you might change. As we gather feedback we’ll apply a bit of sexy to the other stat pages.

wordpress plugin create table on activation

WordPress plugin tutorial, wordpress plugin create table on activation, If you are making plugin and in plugin many times we need to create new tables. In this article I will show you how easily we can create the wordpress plugin.

wordpress plugin create table on activation

wordpress plugin create table on activation
wordpress plugin create table on activation

Using following code you can create the table in wordpress database.

global $jal_db_version;
$jal_db_version = "1.0";

function jal_install () {
   global $wpdb;
   global $jal_db_version;

   $table_name = $wpdb->prefix . "liveshoutbox";
   if($wpdb->get_var("show tables like '$table_name'") != $table_name) {

      $sql = "CREATE TABLE " . $table_name . " (
	  id mediumint(9) NOT NULL AUTO_INCREMENT,
	  time bigint(11) DEFAULT '0' NOT NULL,
	  name tinytext NOT NULL,
	  text text NOT NULL,
	  url VARCHAR(55) NOT NULL,
	  UNIQUE KEY id (id)
	);";

      require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
      dbDelta($sql);

      $rows_affected = $wpdb->insert( $table_name, array( 'time' => current_time('mysql'), 'name' => $welcome_name, 'text' => $welcome_text ) );

      add_option("jal_db_version", $jal_db_version);

   }
}

Now that we have the initialization function defined, we want to make sure that WordPress calls this function when the plugin is activated by a WordPress administrator. To do that, we will use the activate_ action hook. If your plugin file is wp-content/plugins/plugindir/pluginfile.php, you’ll add the following line to the main body of your plugin:

register_activation_hook(__FILE__,'jal_install');

set post excerpt length to limited characters in wordpress

In wordpress 3.0 limiting the excerpt is very easy. the_excerpt function is very useful and helpful in wordpress. In wordpress limiting the excerpt is very easy. With our code you can set post excerpt length to limited characters in wordpress. the_excerpt function is very useful and helpful in wordpress.

set post excerpt length to limited characters in wordpress

set post excerpt length to limited characters in wordpress
set post excerpt length to limited characters in wordpress

In many wordpress theme we used the excerpt. Many times we need to control excerpt characters as per our wordpress theme requirement. You can easily change the excerpt length using wordpress hook.

You just need to open your functions.php file from your wordpress theme folder and put following code in that.

function change_excerpt_length($length) {
    return 100;
}
add_filter('excerpt_length', 'change_excerpt_length');

This filter is used by wp_trim_excerpt() function. By default the excerpt length is set to return 55 words.

register activation hook using in wordpress plugin

wordpress hooks are very important for wp developers. We can use the wp hooks in wordpress plugin and themes. Here in this article I will show you how to register the hook in wordpress plugin. I given the simple code sample which will give you the fare idea about using the wordpress hooks.

register activation hook using in wordpress plugin

register activation hook using in wordpress plugin
register activation hook using in wordpress plugin

register_activation_hook is very important function for creating the wordpress plugin. The function register_activation_hook registers a plugin function to be run when the plugin is activated.
You can use the register_activation_hook as follows:

<!--?<span class="hiddenSpellError" pre="" data-mce-bogus="1"-->php register_activation_hook($file, $function); ?>

If you can going to create the wordpress simple plugin then this function is very useful. this function you can use as follows in files.
If you have a function called myplugin_activate() in the main plugin file at either

* wp-content/plugins/myplugin.php or
* wp-content/plugins/myplugin/myplugin.php

you can use code as follows:

global $myvar;
$myvar='whatever';

function myplugin_activate() {
  global $myvar;
  echo $myvar; // this will be 'whatever'
}

register_activation_hook( __FILE__, 'myplugin_activate' );

1. register_activation_hook() must be called from the main plugin file – the one that has “Plugin Name: …” directive.
2. Your hook function must be in the same file as well. From that function it is ok to call other functions defined in other files.
3. Doing echo “My hook called!”; – does not work from it. So this is not a good way to judge whether it working or not.
4. Your global variables must be explicitly declared as global for them to be accessed from inside of my_activation_hook().

Check the sample wordpress plugin code.

<!--?<span class="hiddenSpellError" pre="" data-mce-bogus="1"-->php
/*
Plugin Name: A Test
Description: A Test
*/

require_once (dirname(__FILE__) . '/my_other_file.php');

// This code *will not* work. Activation hook function must be defined in the main plugin file.
//    register_activation_hook (dirname(__FILE__) . '/my_other_file.php', 'my_other_function');

// This code will work.
register_activation_hook (__FILE__, 'test_activated');

// This is correct way to declare/access globals.
global $some_var;    // globals must be declared explicitly. Without this you will not be able to access '$some_var' from within 'test_activated()' function.
$some_var = 'hey';

//===========================================================================
function test_activated ()
{
   global $some_var; // Now it will be 'hey'.

   // This function is defined in 'my_other_file.php'
   my_other_function ();

   // This will not work, so don't try. If you need logging write something in temporary log file in here via fopen/fwrite.
	// If you want to quickly test if your activation hook works - put exit() into it. At least you'll see error during activation.
   echo 'test_activated called!';
}
//===========================================================================

?>

The function register_deactivation_hook registers a plugin function to be run when the plugin is deactivated.
following function will deactivate your plugin

register_deactivation_hook( __FILE__, 'myplugin_deactivate' );

How can user delete their own account from WordPress site

Creating, editing and deleting the user account is a very basic need of any CMS. We can easily allow user to register their account in wordpress sites. We shown in this article, How can user delete their own account from wordPress site. We can use many wordpress plugins and create User profile and manage their profile.

How can user delete their own account from WordPress site

How can user delete their own account from WordPress site
How can user delete their own account from WordPress site

But in wordpress deleting the User from wordpress site is not easy. Here in this article I will tell how can we easily delete the user account without administrator permission.

Using following wordpress plugin we can achieve this functionality.

User Self Delete

This plugin will allow your users to delete their own account without any need for interaction on the administrator’s behalf.

When a user wishes to delete their account, they are taken to a confirmation page where they must enter the word “yes” in order for the deletion to take place. Once they type “yes” and press the delete account button, they are redirected to the login page and they no longer exist as a user on your site.

How to add pagination in wordpress

Many times adding the custom pagination in wordpress blog is very important. Adding custom pagination in wordpress blog is good. In this article, we will show you, How to add pagination in wordpress with plugin and without wp plugin

How to add pagination in wordpress

  • Simple WordPress Default pagination

You need to open the your index.php file from wordpress theme and put following code in that file.

<div class="navigation">
<div class="alignleft"><?php next_posts_link('Previous') ?></div>
</div>
<div class="alignright"><?php previous_posts_link('Next') ?></div>

If you want the pagination in single post then you can use the following code:

<?php next_posts_link($label , $max_pages); ?>
<?php prev_posts_link($label , $max_pages); ?>

More pagination style visit above URL: wordpress pagination style without wordpress plugin

There are some very nice wordpress plugin available for wordpress pagination.

How to add pagination in wordpress
How to add pagination in wordpress

PageNavi wordpress plugin is really nice. I personally like this plugin so much. With this plugin you can apply your custom css also.

  • Changing the CSS

If you need to configure the CSS style of WP-PageNavi, you can copy the pagenavi-css.css file from the plugin directory to your theme’s directory and make your modifications there. This way, you won’t lose your changes when you update the plugin.

Alternatively, you can uncheck the “Use pagenavi.css?” option from the settings page and add the styles to your theme’s style.css file directly.

code syntax highlighter through wordpress plugins

When ever we write some code in post. That code need to visible very easily. Here are some code syntax highlighter through wordpress plugins which will be useful for developers and coders. There are some useful wordpress plugins for highlighting the code in wordpress post.

code syntax highlighter through wordpress plugins
code syntax highlighter through wordpress plugins

 

code syntax highlighter through wordpress plugins

While WordPress.com doesn’t allow you to use potentially dangerous code on your blog, there is a way to post source code for viewing. We have created a shortcode you can wrap around source code that preserves its formatting and even provides syntax highlighting for certain languages, like so:

To accomplish the above, just wrap your code in these tags:

 your code here
 

The language parameter controls how the code is syntax highlighted. The following languages are supported:

  • actionscript3
  • bash
  • coldfusion
  • cpp
  • csharp
  • css
  • delphi
  • erlang
  • fsharp
  • diff
  • groovy
  • javascript
  • java
  • javafx
  • matlab (keywords only)
  • objc
  • perl
  • php
  • text
  • powershell
  • python
  • ruby
  • scala
  • sql
  • vb
  • xml

If the language parameter is not set, it will default to “text” (no syntax highlighting).

Code in between the source code tags will automatically be encoded for display, you don’t need to worry about HTML entities or anything.

There are some free plugins also helpful for syntax highlighting.  I specially like the SyntaxHighlighter Evolved wordpress plugin. SyntaxHighlighter Evolved allows you to easily post syntax-highlighted code to your site without loosing it’s formatting or making any manual changes.

You can download this plugin form here:

SyntaxHighlighter Evolved

There is another plugin for syntax highlighting which also really nice.

WP-Syntax provides clean syntax highlighting using GeSHi — supporting a wide range of popular languages. It supports highlighting with or without line numbers and maintains formatting while copying snippets of code from the browser.

It avoids conflicts with other 3rd party plugins by running an early pre-filter and a late post-filter that substitutes and pulls the code snippets out first and then pushes them back in with highlighting at the end. The result is source code formatted and highlighted the way you intended.

You can download the this from here:

WP-Syntax

How to Increase Your WordPress Blog Traffic Overnight?

WordPress is used any almost all the blogs as CMS. Many people need the blog traffic for their site. There are many people searching for increasing the traffic of site. Here in this article We given tricks for Increase Your WordPress Blog Traffic Overnight.. Here in this article I found some best tricks to increase blog traffic.

How to Increase Your WordPress Blog Traffic Overnight?

Would you like to increase traffic to your ecommerce business blog overnight?

Believe it or not, this may just be do-able!

How, you ask?

  • With the WordPress OnlyWire Auto Poster plug-in, that’s how!

As you may or may not know, WordPress is probably the most popular and often used blog platform on the World Wide Web according to Technorati. It’s a state of the art publishing platform that focuses on aesthetics, web standards and usability.

How to Increase Your WordPress Blog Traffic Overnight?
How to Increase Your WordPress Blog Traffic Overnight?

Best of all, it’s FREE.

The WordPress Only Wire Auto Poster plug-in can significantly increase traffic to your blog—possibly or even probably—overnight because by using it, you are able to syndicate your blog posts to over 30 of the top social sites simultaneously, with just one click of a button.

No more slogging along doing it the hard way, one at a time. With the OnlyWire plug-in, you are assured of getting your blog post out there where the most people will see it, and hopefully read it.

Just think of how this could help you build valuable backlinks, not to mention improve your website traffic and search engine index speed!

There are two ways to use the WordPress OnlyWire Auto Poster plug-in:

  1. As a Firefox plug-in which will stay in the upper right hand corner of your browser, right next to the Google search bar, or
  2. Install the OnlyWire plug-in from your WordPress blog simply by selecting it from the available WordPress plug-ins, and then clicking install.

It’s just that easy!

OnlyWire is a blogger’s dream come true as a time saver. There are four ways to use it, including the simultaneous submission to social sites feature:

  1. Submission browser button: Syndicates your blog article to 31 social sites at once
  2. Bookmark and share button: This button can be placed on websites and blogs, and allows visitors to share the page on their social networking sites.
  3. Developer API: Automatically submits blog or web content to an existing CMS system at the will of the user.
  4. Account management: A very handy tool within the program that you can use to keep track of everything. It will set up the social sites to be used, show submission history, as well as finalize your submissions to manage a member account.

If you want to save yourself a lot of time on social media marketing, and increase traffic to your blog overnight, then you should take a look at WordPress OnlyWire for your online dropshipping business or other ecommerce enterprise.

http://wordpress.org/extend/plugins/wp-onlywire-auto-poster/

 

how to use update option in wordpress plugin

Most of wordpress plugin writer choose the new table for saving data for plugin setting and any setting in wordpress plugin. In this article we will show, how to use update option in wordpress plugin.  I recommend to use the update option for saving data in wordpress database.

how to use update option in wordpress plugin

how to use update option in wordpress plugin
how to use update option in wordpress plugin

There is ready made option is provided by wordpress to save custom data in there table.

Here with very simple code I will show how use save the data in wordpress database.

&lt; ?php
$variable = array(‘var1′ =&gt; $_POST['var1'], ‘var2′ =&gt; $_POST['var2']);
update_option(‘myPlugin_var1′, serialize($variable));
get_option(‘myPlugin_var1′) == “” ? “” : $new = unserialize(get_option(‘myPlugin_var1′));
?&gt;

You should save data in simple variable format or I suggest always save data in array format.

For more reference you can check the following URL
http://phpxref.com/xref/wordpress/wp-admin/options.php.source.html