How to use the_excerpt in WordPress

We all know what is excerpt. In wordpress using excerpt is good idea. WordPress provides the inbuild function called the_excerpt. Many people want to to show first few words on the theme front page. For that this function is very useful.

How to use the_excerpt in WordPress

How to use the_excerpt in WordPress
How to use the_excerpt in WordPress

If you do not provide an explicit excerpt to a post (in the post editor’s optional excerpt field), it will display an automatic excerpt which refers to the first 55 words of the post’s content. Also in the latter case, HTML tags and graphics are stripped from the excerpt’s content.

Important Note: the_excerpt function must be written in The Loop.
For using the excerpt tag you need to put following code in the loop.

<!--?<span class="hiddenSpellError" pre="" data-mce-bogus="1">php</span> the_excerpt(); ?-->

Some times you need to put excerpt tag conditionally. In archive or category and home page you want to show only the excerpt of post then you can use following code:

<!--?<span class="hiddenSpellError" pre="" data-mce-bogus="1">php</span> if ( is_category() || is_archive() || is_home() ) {-->
	the_excerpt();
} else {
	the_content();
} ?-->

If you want to Control Excerpt Length using Filters use following code. To change excerpt length using excerpt_length filter, add the following code to functions.php file in your theme:

function new_excerpt_length($length) {
return 20;
}
add_filter('excerpt_length', 'new_excerpt_length');

use the_excerpt in WordPress

Tip: You can Remove […] string using Filters.By default, excerpt more string at the end is set to ‘[…]’. To change excerpt more string using excerpt_more filter, add the following code to functions.php file in your theme:

function new_excerpt_more($more) {
	return '[.....]';
}
add_filter('excerpt_more', 'new_excerpt_more');

If you want to make read more link after excerpt then use following code:

function new_excerpt_more($more) {
       global $post;
	return '<a href="'. get_permalink($post->ID) . '">' . 'Read the Rest...' . '</a>';
}
add_filter('excerpt_more', 'new_excerpt_more');

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 do I get wordpress API Key

Many people are running there site with wordpress. For many reasons We need to WordPress api key. For using the wordpress stat and akismet plugin we need the wordpress api key. In this article we given details for get wordpress API Key

How do I get wordpress API Key

How to get the free wordpress api key?

Go to following URL:

http://akismet.com/personal/

How do I get wordpress API Key
How do I get wordpress API Key

Put your email address and click on register button.

How do I get wordpress API Key
How do I get wordpress API Key

Click on use Akismet for free! Link. Than fill all your information in the form and hit the Next button.

After submission you will see the following message.

You will get the wordpress api through wordpress in following format.

Thanks for choosing Akismet.

Your Akismet API key is: ------------

If you have any questions or concerns about your Akismet subscription, don't hesitate to ask:

http://akismet.com/contact/

Thanks,
The Akismet team.

How to Optimize Your WordPress Database using plugin

When we are using the wordpress sites then we need to clean the database always. If your site is having more than 500 articles then you need to worry about server performance.

How to Optimize Your WordPress Database using plugin

Mysql load will impact your server.  Many people are suggesting to use the WP-DBManager wordpress plugin. But forgot about plugin feature. That plugin specially made for database backup and managing the tables.

If you want to optimize your wordpress database then you need to use wp-optimize wordpress plugin. I found that is only plugin is helpful for really keep optimize your wordpress database.

I used that plugin. Before using that plugin my mysql database size was 135mb. After using that wp-optimize plugin features database size was 4mb. That means my database really optimized. My sites performance was also improved.

I really liked this wordpress plugin. Thanks to Ruhani Rabin who wrote this plugin.

How to Optimize Your WordPress Database using plugin
How to Optimize Your WordPress Database using plugin

You can download this plugin from here:

http://wordpress.org/extend/plugins/wp-optimize/

Simple but effective plugin allows you to extensively clean up your WordPress database and optimize it without doing manual queries.

What is features of wp-optimize?

  • Enable/Disable trackbacks for all published post
  • Enable/Disable comments for all published post
  • Removal of stale post revisions
  • Removal of stale unapproved and spam comments
  • Removal of trashed comments
  • Removal of akismet metadata from comments
  • Removal of other stale metadata from comments
  • Mobile device friendly, now you can optimize your site on the go
  • Removal of all trackbacks and pingbacks
  • Cleaning up auto draft posts
  • Removal of transient options
  • Clear out the post trash
  • Automatic cleanup of all the integrated options (also uses retention if enabled)
  • Ability to keep selected number of weeks data when cleaning up
  • Option to add or remove link on wp admin bar.
  • Enable/Disable weekly schedules of optimization
  • Apply native WordPress MySql optimize commands on your database tables without phpMyAdmin or any manual query.
  • Display Database table statistics. Shows how much space can be optimized and how much space has been cleared.
  • Enabled for Administrators only.

Every-time you save a new post or pages, WordPress creates a revision of that post or page. If you edit a post 6 times you might have 5 copy of that post as revisions. Imagine if your post or pages are long and big. It is a huge number of bytes that’s on your MySQL overhead. Now WP-Optimize allows you to optimize and shrink your posts table by removing not necessary post revisions from the database. As example, if you have a post which is approximately 100KB data and you have 5 revisions of that post, the total space wasted is about 500KB. And if you have 100 posts similar to it, you have 50MB database space wasted.

wordpress show latest post from each category

Many people want to show wordpress show latest post from each category posts from there selected categories or all categories on home page. Here we given code snippet for this.
I this article I will show how easily you can achieve this.

wordpress show latest post from each category

Please following code in your home page which is your theme’s index.php file.

&lt;!--?&lt;span class=&quot;hiddenSpellError&quot; pre=&quot;&quot; data-mce-bogus=&quot;1&quot;&gt;php&lt;/span&gt;--&gt;
$categories=get_categories($all_categories);
 foreach($categories as $category) {
 $post_args=array(
 'showposts' =--&gt; 1, // you can fetch number of articles from each category
 'category__in' =&gt; array($category-&gt;term_id),
 'caller_get_posts'=&gt;1
 );
 $posts=get_posts($post_args);
 if ($posts) {
 echo '&lt;/pre&gt;
Category: sprintf( __( &quot; href=&quot;' . get_category_link( $category-&gt;term_id ) . '&quot;&gt;name ) . '&quot; ' . '&gt;' . $category-&gt;name.'&lt;/pre&gt;
&lt;pre&gt; ';foreach($posts as $post) {&lt;/pre&gt;
&lt;pre&gt;
 setup_postdata($post); ?&gt;&lt;/pre&gt;
&lt;div&gt;

php the_title_attribute(); ?&gt;&quot; href=&quot;&lt;!--?php the_permalink() ?--&gt;&quot; rel=&quot;bookmark&quot;&gt;
 &lt;!--?&lt;span class=&quot;hiddenSpellError&quot; pre=&quot;&quot; data-mce-bogus=&quot;1&quot;&gt;php&lt;/span&gt; the_title(); ?--&gt;

&lt;!--?&lt;span class=&quot;hiddenSpellError&quot; pre=&quot;&quot; data-mce-bogus=&quot;1&quot;&gt;php&lt;/span&gt; the_excerpt(); ?--&gt;

&lt;/div&gt;
&lt;pre&gt;
 &lt;!--?&lt;span class=&quot;hiddenSpellError&quot; pre=&quot;&quot; data-mce-bogus=&quot;1&quot;&gt;php&lt;/span&gt;--&gt;
 } // foreach($posts
 } // if ($posts
 } // foreach($categories
?--&gt;

if you want to show the posts from specific articles then use following code.

&lt;!--?&lt;span class=&quot;hiddenSpellError&quot; pre=&quot;&quot; data-mce-bogus=&quot;1&quot;&gt;php&lt;/span&gt;--&gt;
$selected_categories=array(
 'include' =--&gt; '1,4,9',
 'order' =&gt; 'ASC'
 );

$categories=get_categories($selected_categories);foreach($categories as $category) {
 $post_args=array(
 'showposts' =&gt; 1, // you can fetch number of articles from each category
 'category__in' =&gt; array($category-&gt;term_id),
 'caller_get_posts'=&gt;1
 );
 $posts=get_posts($post_args);
 if ($posts) {
 echo '&lt;/pre&gt;
Category: sprintf( __( &quot; href=&quot;' . get_category_link( $category-&gt;term_id ) . '&quot;&gt;name ) . '&quot; ' . '&gt;' . $category-&gt;name.'&lt;/pre&gt;
&lt;pre&gt; ';foreach($posts as $post) {&lt;/pre&gt;
&lt;pre&gt;
 setup_postdata($post); ?&gt;&lt;/pre&gt;
&lt;div&gt;

php the_title_attribute(); ?&gt;&quot; href=&quot;&lt;!--?php the_permalink() ?--&gt;&quot; rel=&quot;bookmark&quot;&gt;
 &lt;!--?&lt;span class=&quot;hiddenSpellError&quot; pre=&quot;&quot; data-mce-bogus=&quot;1&quot;&gt;php&lt;/span&gt; the_title(); ?--&gt;

&lt;!--?&lt;span class=&quot;hiddenSpellError&quot; pre=&quot;&quot; data-mce-bogus=&quot;1&quot;&gt;php&lt;/span&gt; the_excerpt(); ?--&gt;

&lt;/div&gt;
&lt;pre&gt;
 &lt;!--?&lt;span class=&quot;hiddenSpellError&quot; pre=&quot;&quot; data-mce-bogus=&quot;1&quot;&gt;php&lt;/span&gt;--&gt;
 } // foreach($posts
 } // if ($posts
 } // foreach($categories
?--&gt;

How to clean up and optimize wordpress database

Keeping your wordpress database is very important for wordpress database. In this article we explained, How to clean up and optimize wordpress database. This will improve your site speed aslo. Many times you install the wordpress plugins and some time you dont want that plugins and you delete that plugins.

How to clean up and optimize wordpress database

There is very nice wordpress plugin is avilable for database backup.

WP-DB-Backup

WP-DB-Backup allows you easily to backup your core WordPress database tables. You may also backup other tables in the same database.
But that plugins create some tables in your wordpress database. You need to remove that tables from your wordpress database.
Imp note: when ever you are cleaning the database or deleting the unwanted tables from wordpress database. Please consult with your web administrator.
Dont forget to take a full backup of your database.

This tutorial should be forward-compatible with WordPress 3.0

  • Install WP-DB-Backup by Austin Matzko
  • Mouse over Tools so that the down arrow appears
  • Click the down arrow
  • Click Backup
  • You’ll see something like this:
How to clean up and optimize wordpress database
How to clean up and optimize wordpress database

On the left are the default database tables included with WordPress. All of these are included every time you backup. The only thing you have to decide here is whether to exclude spam comments from being backed up (I recommend this) and whether to exclude post revisions (I recommend excluding these too, unless you have a specific reason for keeping revisions).

On the right is a list of additional database tables, most of which were probably created by plugins. There’s also a table called that will end with the name “commentmeta” – this can be used by plugins.

If your plugins have created a lot of data that you would like to save, or you’ve spent a lot of time configuring particular plugins, you’ll want to backup these tables. Otherwise, you can keep your database backups smaller by not checking them.

  • Next we see the Backup Option. There are three choices here:

A. Save to the server

This will save a backup of your database as a file on your web server. I don’t recommend this.

B. Download to your computer.

This will create a database backup file that you can save to your local computer.

C. Email backup to:

This allows you to send a copy of the backup to any e-mail address you’d like.

  • Let’s go ahead and download a copy to our hard drives now.

Check options you want in the Tables section then click “Backup now!”

You should see a progress bar, and when that’s done your browser will prompt you to save the file. You can save this file wherever you’d like.

  • There’s another section called “Scheduled Backup.” This is where this program gets really great.

Here we can schedule a backup to be e-mailed to a particular e-mail address however often we’d like. I recommend checking selecting “Once Daily.”

  • On the right, you’ll see that list of optional tables again. Check the ones you want to backup every time the backup runs.
  • Enter the e-mail address you want the backups delivered to in the “Email backup to:” field.
  • Click “Schedule backup.”
  • You should now get a backup file as an e-mail attachment every day. You should save these attachments to your local computer. If you’re using Gmail or another web mail host that has a lot of storage space, you might want to leave your databases on their server as an additional off-site backup. Be aware that that’s an additional security risk – if your e-mail account is ever compromised, the would have access to all of your database backups.

how to do persistent database connection in wordpress

Here in wordpress tutorial, we explained, how to do persistent database connection in wordpress. Persistent connections are links that do not close when the execution of your script ends.

What is persistent database connection?

Persistent connections are links that do not close when the execution of your script ends. When a persistent connection is requested, PHP checks if there’s already an identical persistent connection (that remained open from earlier) – and if it exists, it uses it. If it does not exist, it creates the link. An ‘identical’ connection is a connection that was opened to the same host, with the same username and the same password (where applicable).

how to do persistent database connection in wordpress
how to do persistent database connection in wordpress

If you want to use the persistent database connection then you should follow my steps:

how to do persistent database connection in wordpress

First Open the wp-db.php file from wp-includes folder. In that file find following words:


// @mysql_connect( $dbhost, $dbuser, $dbpassword, true );

//Change that to

@mysql_pconnect( $dbhost, $dbuser, $dbpassword, true );

comment the mysql_connect line. This line you will find two times in that file. You need to change the line both the times. Then upload this file to your wordpress installation.

Persistent database connection will open only one connection and for every query that will check for connection is present or not. If connection is already present then your query will execute using that persistent database connection.

There are couple of issues with persistent database connection, When you are using the persistent connection you should keep following things in mind.

Imp: There are a couple of additional caveats to keep in mind when using persistent connections. One is that when using table locking on a persistent connection, if the script for whatever reason cannot release the lock, then subsequent scripts using the same connection will block indefinitely and may require that you either restart the httpd server or the database server. Another is that when using transactions, a transaction block will also carry over to the next script which uses that connection if script execution ends before the transaction block does. In either case, you can use register_shutdown_function() to register a simple cleanup function to unlock your tables or roll back your transactions. Better yet, avoid the problem entirely by not using persistent connections in scripts which use table locks or transactions (you can still use them elsewhere).

How to publish wordpress feeds later

When you publish your post,the feed an published to the whole world.That’s very annoying thing. publish wordpress feeds later, That is always good from SEO.

How to publish wordpress feeds later

How to publish wordpress feeds later
How to publish wordpress feeds later

Some times you need to change the content or change the url, that time you got the errors

The following example publishs the post 10 minutes later in your feed:


/**
 * puplish the content in the feed later
 * $where ist default-var in WordPress (wp-includes/query.php)
 * // Apply filters on where and join prior to paging so that any
 * This function an a SQL-syntax
 */
function publish_later_on_feed($where) {
 global $wpdb;

 if ( is_feed() ) {
 // timestamp in WP-format
 $now = gmdate('Y-m-d H:i:s');

 // value for wait; + device
 $wait = '10'; // integer

 // http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_timestampdiff
 $device = 'MINUTE'; //MINUTE, HOUR, DAY, WEEK, MONTH, YEAR

 // add SQL-sytax to default $where
 $where .= " AND TIMESTAMPDIFF($device, $wpdb->posts.post_date_gmt, '$now') > $wait ";
 }
 return $where;
}

add_filter('posts_where', 'publish_later_on_feed');

You need to open the your wordpress themes functions.php file and put above code in that file. Using this function your feed will publish after 10 minute of your wordpress post publishing.

increase the upload_max_filesize in WordPress

The default upload file size is in php settings is 2 MB and for wordpress also default upload size is 2 MB. File upload size is dependent on PHP settings of your server. Upload size is also dependent on your hosting plan or hosting service provider. For shared hosting most of time you cannot increase the file upload limit.

increase the upload_max_filesize in WordPress

When we try to upload big size image or media files in wordpress we got the following error

The uploaded file exceeds the upload_max_filesize directive in php.ini
For fixing the issue use following steps
Use the php.ini file from root folder.

1. Find this line in the php.ini file in your php installation upload_max_filesize = 2MB and replace it with a higher value (e.g. upload_max_filesize = 64MB)
2. Search for this line in your php.ini file post_max_size and increase it.

If you don’t have a php.ini file in your directory,
you can usually generate one from the control panels of your host. or create the file and put following values in that
memory_limit = 32M
upload_max_filesize = 100M
upload_max_filesize = 100M
post_max_size = 100M

increase the upload_max_filesize in WordPress
increase the upload_max_filesize in WordPress

This file is copied into your wp-admin folder, the problem should be solved.

Ten wordpress plugins for improve User interactivity

When you are developing the website or blog using wordpress. You need to think about readers experience on your website. Keeping user experience in mind I created the list of wordpress plugins which are very useful for user interactivity and experience.

 

Ten wordpress plugins for improve User interactivity and experience

1. WP-Print

This Plugin displays a printable version of your blog when the reader requests for it. The user can directly take a print out from it. The documentation can be found here.

There is also another print widget by HP. This adds a print option to your blog posts. This plugin is available for WordPress and Movable type. This plugin can also convert blog posts into PDF files.

Download WP-Print

2. Convert to PDF

Converting your blog posts into PDF is useful when your blog has more content on tutorials and tips & tricks. Amit has written a post on how to save the blog posts to PDF file. Adding a “Save as PDF” button is really simple process. All you need is to add this link at the end of blog posts (for WordPress users).

http://savepageaspdf.pdfonline.com/pdfonline/pdfonline.asp?cURL=php the_permalink();?>

Blogger users can update the cURL link with the post permalink. This generates a PDF file which can be saved to hard disk.

3. Related Posts

As the name indicates, this plugin will show the related entries for a particular post based on keyword matching.

Download Related Posts

4. WP-Email

This Plugin helps readers to share posts on blogs which they liked with their friends or even to their email. The plugin is easy to use and configure. The documentation can be found here.

Download WP-Email

5. Subscribe to Comments

Subscribe to Comments 2.1 is a plugin that allows commentators on your blog to check a box before commenting and get e-mail notification of further comments. This is useful to have a good discussion going on in your posts.

Download Subscribe to Comments

6. Popular Contest / Top Posts by Category

Popularity contest will help you see which of your posts are most popular and the Top posts plugin displays your top rated posts categorywise based on comments or page views.

Download Top Posts by Category

7. Related posts in your Feed

This WordPress plugin adds a list of Related Posts to your full text feed. For this plugin to work properly you need Related Posts plugin or Ultimate Tag Warrior

plugin activated.

Download Related posts in your Feed

8. qTranslate

Ten wordpress plugins for improve User interactivity
Ten wordpress plugins for improve User interactivity

Multilingual support is one of the biggest missing features of WordPress, but with qTransalate you can easily accomplish the task of managing different languages for your blog site.

http://www.qianqin.de/qtranslate/

9. Contact Form 7

Even though there are tens of contact form plugins out there, I’ve always liked Contact Form 7. The problem with most contact form plugins is that either they are too simple or way too complex. Contact Form 7, on the other hand, is extensible yet easy-to-use. It supports Ajax-powered submitting, multiple forms, CAPTCHAS, and Akismet spam filtering.

http://wordpress.org/extend/plugins/contact-form-7/

 

10. Display Thumbnails For Related Posts in WordPress

by adding thumbnails to related posts using the popular YARPP plugin and WordPress custom fields
http://buildinternet.com/2009/07/display-thumbnails-for-related-posts-in-wordpress/