How to change length of Excerpt in WordPress

As a WordPress developer, i needed to change the length of the excerpt.
You can add following function in your themes’s functions.php file.

if(!function_exist('new_excerpt_length') {
    function new_excerpt_length($length) { 
       return 100;
    }
}
add_filter('excerpt_length', 'new_excerpt_length');

Above function will change the excerpt length to 100. (You can change that value as per your need).

Useful Full Forms

Below you can find some useful full forms.

Technical

PHP : Hypertext Preprocessor
PEAR : PHP Extension and Application Repository
Ajax : Asynchronous JavaScript and XML
SOAP : Simple Object Access Protocol
HTML : Hypertext Markup Language
CSS : Cascading Style Sheets
SQL : Structured Query Language
ANSI : American National Standards Institute
DBMS : Database Management System
RDBMS : Relational Database Management System
DDL : Data Definition Language
DML : Data Manipulation Language
GIF : Graphics Interchange Format
JPEG : Joint Photographic Experts Group
MPEG : Moving Picture Experts Group
PNG : Portable Network Graphics
AVI : Audio Video Interleaved
HTTP : Hypertext Transfer Protocol
W3C : World Wide Web Consortium
IETF : Internet Engineering Task Force
IRTF : Internet Research Task Force
APC : Alternative PHP Cache
APD : Advanced PHP debugger
SVN : Subversion (version control system)
PDO : PHP Data Objects
FTP : File Transfer Protocol
SFTP : Secure File Transfer Protocol
CGI : Common Gateway Interface
DOM : Document Object Model
JSON : JavaScript Object Notation
MSI : Microsoft Installer

Non-technical

NEWS : North East West South
WHO : World Health Organization

Detect an AJAX Request in PHP

Whenever you need to check if request is Ajax or non-Ajax, you can check it using following code.

if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
echo "This is an Ajax Request";
}else {
echo "Not an Ajax Request";
}

Reference : http://davidwalsh.name/detect-ajax

WordPress – Add pagination in admin listing page

When you need to add pagination in WordPress admin listing, just follow below steps:


$page_num = isset( $_GET['pagenum'] ) ? absint( $_GET['pagenum'] ) : 1;
$limit = 10; // Number of rows in page
$offset = ( $page_num - 1 ) * $limit;
$total = $wpdb->get_var( "SELECT COUNT(`id`) FROM `wp_posts`" );
$num_of_pages = ceil( $total / $limit );
$lists = $wpdb->get_results("SELECT * FROM `wp_posts` ORDER BY id ASC LIMIT $offset,$limit" );


$page_links = paginate_links( array(
'base' => add_query_arg( 'pagenum', '%#%' ),
'format' => '',
'prev_text' => __( '«', 'text-domain' ),
'next_text' => __( '»', 'text-domain' ),
'total' => $num_of_pages,
'current' => $pagenum
) );


if ( $page_links ) {
echo '<div class="tablenav"><div class="tablenav-pages" style="margin: 1em 0;">' . $page_links . '</div></div>';
}

Leave comments if you find it useful or you have any query about this.

Mysql – Calculate database size

You can calculate MySql database size using following steps.

Login into mysql :

mysql -h hostname -u username -p

Above command will ask you to enter mysql password.
After log in into mysql, run following query.

SELECT table_schema "DatabaseName",
sum( data_length + index_length ) / 1024 / 1024
"DataBase Size in MB" FROM information_schema.TABLES
GROUP BY table_schema;

Just replace your Database name. Thats it.
Please leave your comments if it worked for you.

Install eclipse in ubuntu-linux

Install Eclipse

Type the following command to install extensible Tool Platform, Java IDE, Java Development Tools plug-ins for Eclipse:
$ sudo apt-get install eclipse eclipse-jdt

How to start eclipse?

Click on Applications > Programming > Eclipse

OR type the following command at shell prompt:
$ eclipse &

Done. Enjoy

WordPress – Use php variables in javascript function

In WordPress , sometimes you need to use your PHP variable into included javascript file. You can use below function for this.

wp_register_script( 'myscript', FB_LIKE_PLUGIN_URL . 'fb.js' , array('jquery'), '2.5.4.6' );
wp_enqueue_script( 'myscript' );
$local_variables = array('app_id' => $app_id,'name' => "Milap");
wp_localize_script( 'myscript', 'vars', $local_variables );

wp_register_script function include my own created javascript file from plugin directory and also include jquery file.
$local_variables contains array in which you have to pass all variables with key which you want to access into your fb.js file.
wp_localize_script function will pass this array into js file & you can access theses variables in javascript file like vars.app_id and vars.name !!

Let me know , if you have any confusion ..